sprintf
22 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I'm trying to get sprintf to print out a line that says: 'for event ----- stations pass the criteria test=' where it will list the results for my stations vertically like:
U02B.HHZf
U04B.HHZf
U05B.HHZf
U06B.HHZf
and so on. I can't seem to get it to do this..it keeps combining my stations together something like UUU00452648BBBB....HHHHHZZZZZfffff. I'm looking at the help pages but there are few examples, any suggestions? This is what I've written so far:
u=char(files(keep==1));
str1=sprintf('for event %s stations passed criteria
test=%f\n',char(dirs(i)),char(u));
disp(str1)
where u= U02B.HHZf
U04B.HHZf
U05B.HHZf
U06B.HHZf
and dirs(i) corresponds to my directories. Any suggestions or help in what I'm doing wrong?
Kayle
0 comentarios
Respuestas (4)
Walter Roberson
el 12 de Jul. de 2011
Using a for loop for that would be easiest, probably.
Question: what value is it that you are trying to print out with the %f numeric format?
0 comentarios
Voss
el 28 de En. de 2025
files = {'U02B.HHZf';'U04B.HHZf';'U05B.HHZf';'U06B.HHZf'};
keep = true(size(files));
dirs = {'some\directory'};
i = 1;
tmp = sprintf('%s\n',files{keep==1});
str1 = sprintf('for event %s stations passed criteria test=\n%s',char(dirs(i)),tmp);
disp(str1)
0 comentarios
Steven Lord
el 28 de En. de 2025
This wasn't an option when the question was originally asked, but in more recent releases I recommend storing the names as a string array.
S = ["U02B.HHZf"
"U04B.HHZf"
"U05B.HHZf"
"U06B.HHZf"]
passed = [true true false true] % 5B didn't pass, the others did
sprintf("For event, station passed criteria test=%s\n", S(passed))
Or to display the header only once:
sprintf("For event, stations passed criteria test=\n%s", sprintf("%s\n", S(passed)))
0 comentarios
Ver también
Categorías
Más información sobre File Operations 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!