Input(variable)=('','s'); doesn't work? How would it work?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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.
0 Commenti
Risposta accettata
Jan
il 14 Nov 2012
Modificato: Jan
il 14 Nov 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".
Più risposte (0)
Vedere anche
Categorie
Scopri di più su MATLAB Report Generator in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!