Matlab - Structure Arrays? Need some help on some functions

Thread Starter

Judas543

Joined Jan 26, 2010
60



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)
 

johndoe45

Joined Jan 30, 2010
364
been busy. so sorry that i can't help. have project due monday. test that took today. and test on thursday.

plus your posts are getting harder and harder and i know nothing about words in Matlab still. i don't think we are going to cover that. we are engineers so no idea why would use strings anyway.
 

Ghar

Joined Mar 8, 2010
655
I just spent a lot of time using Matlab strings as an engineer.
I had to parse text format logs of various things from a large robot.
I also had to do a lot of text parsing for the same project just to automate plotting the data.

Strings are a pretty basic and useful thing to know. You can also convert a string into a function call so you can generate code with code.

Too bad I'm too late to actually help.
 
Top