What I need help is this:
Modify an entry in the DataBase (e.g., a value has been entered mistakenly as a number instead of a string)
*1)Obviously I know how to do this by indexing it like calling its structure name.
But how would I do that in a script, like without doing it to a specific name. In essense so the user chooses which item to choose to modify.
2)Sell an item and modify the store inventory accordingly
I have no clue to do this, I was thinking of doing rmfield(Products,'something goes here')
However it will effect both elements in the structure, i only want to effect one item and decrease the item inventory entered to decrease by the amount. So if the original inventory was (100), if a user wanted to sell an item, it will be (99)
If someone could enlighten me on how to do this, that would be great!
Creation of structure =
1) Structure for storing the products sold at a store
2) Start the structure by entering in the script the information for the first product
*I just entered random info
3) SAVE structure workspace
%%%%%%%%%%%%%%%%%%%
clc,clear
Products = struct('Name',[],'SKU',[],'Retail',[],'nItems',[]) %Creates Empty Structure
Products.Name = 'Pencil Sharpener' % Product Name
Products.SKU = '123456789' %SKU Number
Products.Retail = 0.3000 %Product Price
Products.nItems = 100 %Number of items in stocky
save mProduct.mat %Saves workspace
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%function file
function [p] = makeEntry(pName,pSKU,pRetail,pItem)
%Makes a function that will help create a new entry
%Our inputs are run through our function to get a new field in our
%structure
p.Name = pName
p.SKU = pSKU
p.Retail = pRetail
p.nItems = pItem
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Main Script
%Part of it
%Thats to add a new entry into the Products
case 1
pName = input('Product Name:','s');
pSKU =input('Product SKU:','s');
pRetail =input('Retail Price:','s');
pItem = input('Inventory Number:');
x = length(Products);
Products(x+1) = makeEntry(pName,pSKU,pRetail,pItem)