Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
Rafael Monteiro
Rafael Monteiro el 14 de Nov. de 2012
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.

Respuesta aceptada

Jan
Jan el 14 de Nov. de 2012
Editada: Jan el 14 de Nov. de 2012
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 comentario
Rafael Monteiro
Rafael Monteiro el 14 de Nov. de 2012
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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre MATLAB Report Generator en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by