Input(variable)=('','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.
댓글 수: 0
채택된 답변
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".
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Statics and Dynamics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!