Input(vari​able)=('',​'s'); doesn't work? How would it work?

2 次查看(过去 30 天)
Hey, I'm learning matlab in the university but my teachers aren't very helpful. I need to make this error go away in order to continue my group work which is due november 25th. The program I'm making should work as a database in which the user can store materials such as metals, ceramics and plastics (with their respective properties associated) and also view the data that was stored stored. So far I've been able to load the database and create a new one if it doesn't exist.
The code I have an error in is as follows:
%%Beginning - Loading/Creating datafile.mat
mati =0;
if exist('datafile.mat', 'file')
load('datafile.mat')
else
save('datafile.mat','mati');
end
mati = mati+1;
%%Let the errors begin:
disp('Do you wish to enter a new material?');
inpmat = input('','s');
if strcmpi(inpmat,'yes')
disp('Enter the type of the new material');
tipomat(mati)=input('Metal/Ceramic/Plastic: ','s'); % <-- Error here!
end
Would really appreciate some insight on this. "Subscripted assignment dimension mismatch."
I can store numbers with
dens(mati)=input('Enter the density of the material [Kg/m3]');
but it seems that saving that in a string doesn't work. My issue here is that I need to enter the type and name of the material while being able to let matlab automatically associate each name to its type and properties, such as density, fusion temperature, strain, stress, etc.

采纳的回答

Jan
Jan 2012-11-14
编辑:Jan 2012-11-14
A string is a vector of type CHAR. Therefore it is not a scalar, if it has more than 1 character. In consequene this fails:
tipomat(mati) = 'your input';
To store strings, a "cell string" is apropriate:
tipomat{mati} = 'your input'; % Curly braces
You can store variables of different type in a "cell" array. If only strings are stored in a cell, it is called "cell string".
  1 个评论
Rafael Monteiro
Rafael Monteiro 2012-11-14
Thanks a lot for this! But how will I now associate this cell string to the rest of the strings? For example, in order to display the data for mati = 1 which would be iron, for example. If I have the following stored in my datafile.mat
tipomat{mati} = Metal
namemat{mati} = Iron
dens(mati) = 5
fpoint(mati) = 1700
maxstress(mati) = 840

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB Report Generator 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by