help with concatenation to open file
Show older comments
hello, can anyone help me to make this concatenation work?
I need a routine that ask the user to type the word 'work' and number '2' and also, only permits receive the answer 'work' and '2'
i tought something like this
% enter the right name of the file
work = inputdlg (a);
t=str2num(char(work));
_if t =~ work
..._
% enter the right number of the file
number = inputdlg (b);
n=str2num(char(number(1)));
if n~=2
disp('ERROR: Please type 2');
else
% concatenate
name = [ t, '_' , n ];
name_file = [ name, '.txt' ];
load (name_file);
thx :)
1 Comment
dpb
on 23 Oct 2013
Well, if you're only going to allow one answer, why make the user work (so to speak)? Just define it.
But, the general question -- to compare a string
doc strncmp % and friends
To compare numeric, just use '==' or for arrays see
doc isequal
As a stylistic note, dereference the cell array contents with the curly braces "{}" instead of using char()
n=str2num(num{1});
This kind of logic is also a good location for a while...end loop enclosing a try...catch block to handle error and repeat the question until proper answer is obtained (or user gives up in frustration--don't forget to have a way to exit)
Accepted Answer
More Answers (1)
Categories
Find more on Time Series Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!