replace the command 'set' in GUI

Hello...
how can I use the command 'set' in the GUI in matlab that it can keep the previous answer and not to replace it with the new one. like for example, when I use a for loop and get more than one output, in the normal matlab code it will keep all outputs and print it in the screen as the following:
for i=2:length(contextt)
if ~isequal(co1,co2)
if strcmp(q,pc) || ~ismember(tt1(length(tt1)),tt3)
fprintf('RKC = { %s , %s }\n',pc,cc)
set(textA,'string',['RKC = {',pc ,',', cc,'}']);
end
end
end
the result will be the follwoing:
answer = { a0.b0.d6 , a0.c0 }
answer = { a0.c0 , a0.c0.d5 }
answer = { a0.c1.b2.d13 , a0.c1.c3 }
but in the GUI version, when I type:
set(textA,'string',['answer = {',pc ,',', cc,'}']);
it will give me only the last answer means that it updates the answer every time the for loop begins:
answer={a0.d2.c2 , a0.d2.c2.d10}
so is there any command in GUI that can keep answers and put each answer in one line like the fprintf does..
Thank you

Respuestas (1)

Walter Roberson
Walter Roberson el 22 de Dic. de 2012

0 votos

There is no set() that will keep the existing information and add more to it. You need to get() the previous information, add the new information to it, and set() that as the new data.

9 comentarios

Walter Roberson
Walter Roberson el 22 de Dic. de 2012
The answer to your edited question is still "No". You still need to retrieve the previous information, add to it, and set the result as the new version.
Image Analyst
Image Analyst el 22 de Dic. de 2012
And you might need to use "drawnow" to force it to update your screen. Often when you're in an intensive loop, the loop goes much faster than the screen updates and so it looks like it is only doing the last one when it actually is doing them all and it just doesn't have time to refresh the screen before it's on to the next loop iteration. Put drawnow after your set() command.
Jwana
Jwana el 22 de Dic. de 2012
Editada: Jwana el 22 de Dic. de 2012
thank you very much for your support.. I make a code that it saves the previous inofmration and save it in another matrix as follows:
str='';
str1='';
for i=2:length(contextt)
if ~isequal(co1,co2)
if strcmp(q,pc) || ~ismember(tt1(length(tt1)),tt3)
str={pc , cc};
str1=[str; str1];
end
end
end
end
set(textA,'string',str1);
but the problem is that it shows the result line by line as:
'a0.d2.c2'
'a0.d2.c2.d10'
'a0.c1.c3'
'a0.c1.c3.d12'
'a0.c1.b2.d13'
'a0.c1.c3'
'a0.c0'
'a0.c0.d5'
'a0.b0.d6'
'a0.c0'
I need them to show like this :
RKC =
{ 'a0.d2.c2' , 'a0.d2.c2.d10'}
{ 'a0.c1.c3' , 'a0.c1.c3.d12'}
{ 'a0.c1.b2.d13' , 'a0.c1.c3' }
{ 'a0.c0' , 'a0.c0.d5' }
{ 'a0.b0.d6' , 'a0.c0' }
Image Analyst
Image Analyst el 22 de Dic. de 2012
Editada: Image Analyst el 22 de Dic. de 2012
Use sprintf() to get it to look any way that you want.
str1 = sprintf('..........
Walter Roberson
Walter Roberson el 22 de Dic. de 2012
What pattern should be used? "two across and as many rows as needed" ? "5 down and as many columns as needed"? Or does the information inherently come in sets that should all be presented on line line?
Jwana
Jwana el 22 de Dic. de 2012
Editada: Jwana el 22 de Dic. de 2012
@Walter Robenson.. it should be 2 columns ( pc and cc columns) with any number of rows... thnx
Jwana
Jwana el 22 de Dic. de 2012
@Image Analyst.. thank you for the comment.. I used this command as:
str2=sprintf('RKC = { %s }',str1);
but it gives error msg that says:
??? Error using ==> sprintf
Function is not defined for 'cell' inputs.
Error in ==> RKC_FOR_2_INPUTS_str at 497
str2=sprintf('RKC = { %s }',str1);
Try this:
str2=sprintf('RKC = { %15s %22s}',str1{1}, str1{2});
Use whatever field widths you want.
Jwana
Jwana el 22 de Dic. de 2012
@ Image Analyst...it works with str=sprintf('RKC = { %22s , %22s }',pc, cc); !! thank you :)

La pregunta está cerrada.

Etiquetas

Preguntada:

el 22 de Dic. de 2012

Cerrada:

el 20 de Ag. de 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by