Trying to request user input and then perform if elseif else end function...
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Louise Wilson
am 29 Aug. 2019
Kommentiert: Stephen23
am 29 Aug. 2019
I have a for loop which generates a figure on each loop. Based on what I see in the figure, I want my code to request a user input of either Y or N.
Then, on input of either Y or N, I would like to add a row to an output matrix, which I will ultimately write to a .csv.
The first column in each row will be the filename of the figure, and the second column, either 'yesboat' or 'notboat' depending on whether the input is Y or N.
This code isn't working AT ALL but it's what I have pulled together from the help files... if you have any suggestions to make it work, I would be very grateful.
Also, which is the best way to create an empty output for storing text info. such as this? My filenames are numbers at the moment but I would like them to be stored as text.
%create output array, table with two columns
output=[];
row=1;
prompt='Can you see boat noise? Y/N';
x=input(prompt);
if x=='Y'
%store filename in output with 'boat' in second column
output(row,1) = filename; %e.g.5103.190828112504 /variable.yymmssHHMMSS
output(row,2) = 'yesboat';
elseif x==N
%store filename in output with 'no boat' in second column
output(row,1) = filename;
output(row,2) = 'noboat';
else
disp('Input must be Y or N!')
end
row=row+1;
0 Kommentare
Akzeptierte Antwort
Stephen23
am 29 Aug. 2019
"...which is the best way to create an empty output for storing text info..."
Use a cell array or a string array, e.g.:
out = cell(N,2);
for row = 1:N
prompt='Can you see boat noise? Y/N';
x = input(prompt,'s'); % need 's'
switch upper(x)
case 'Y'
out{row,1} = filename;
out{row,2} = 'yesboat';
case 'N'
out{row,1} = filename;
out{row,2} = 'noboat';
otherwise
...
end
2 Kommentare
Stephen23
am 29 Aug. 2019
"...any ideas why this '8___ ' appears?"
It looks like MATLAB might be in some debugging mode. Do you have any breakpoints set?
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Type Identification finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!