1

I want to show my output in a msgbox so I have used msgbox(num2str(output)) but I want to name each line, eg:

Red    25
Green  52
Yellow 88

but when I try to do that it says

Error using horzcat
     CAT arguments dimensions are not consistent.

And when that window pops up and the user press OK then another window will pop up asking

W = questdlg('Would you like to retrain or test the network?', ...
        'Artificial Neural Network', 'Retrain', 'Test', 'Exit', 'Exit');

So, how can format my msgbox and as soon as the OK button is pressed another window will popup?

Any help would be appreciated!

Thanks!

MZimmerman6
  • 8,445
  • 10
  • 40
  • 70
Chrysovalando
  • 97
  • 2
  • 8

2 Answers2

2

For your first question, you can use cell array notation to format your message box text:

rVal = 25;
gVal = 35;
bVal = 45;
msg = {['Red   ',num2str(rVal)];...
       ['Green ',num2str(gVal)];...
       ['Blue  ',num2str(bVal)]};

This allows you to vertically concatenate multi-length strings.

If your output is an Nx1 column vector, you can always format it in this manner using cellfun:

output = [25;35;45];
msgTxt = {['Red   '];['Green '];['Blue  ']};
msgNum = cellfun(@num2str,num2cell(output),'UniformOutput',false);
msg = cellfun(@(x,y) [x,y],msgTxt,msgNum,'UniformOutput',false);

As long as you match the msgTxt size with the output size, this should work fine for any size of the output variable.

As for making your program wait on the user response, try uiwait:

mH = msgbox(msg);
uiwait(mH)
disp('Let''s continue...')
Doresoom
  • 7,398
  • 14
  • 47
  • 61
  • yes it does! thank you! :) can you explain to me a bit more what is the `'UniformOutput'` and the `false` bit? or are they from the definition of cellfun? – Chrysovalando Aug 06 '13 at 14:30
  • 1
    They tell cellfun that it needs to output the results to a cell array because they won't all be the same size/type. If cellfun has a uniform logical or numeric output, it isn't necessary. – Doresoom Aug 06 '13 at 15:31
0

msgbox can be formatted like this

R=23;G=35;B=45; %given values

    (msgbox({['Red ',num2str(R)];['Green ',num2str(G)];['Blue ',num2str(B)]; }));

After your later part of the question

uiwait(msgbox({['Red ',num2str(R)];['Green ',num2str(G)];['Blue ',num2str(B)]; }));

W = questdlg('Would you like to retrain or test the network?', ...
        'Artificial Neural Network', 'Retrain', 'Test', 'Exit', 'Exit');
Zero
  • 74,117
  • 18
  • 147
  • 154
  • thanks but every time the result is different.. so instead of being 25 it would be 6.. is there a way I can name each row and then MATLAB would automatically align the first line with the first row and so on? – Chrysovalando Aug 06 '13 at 13:34
  • @Chrysovalando Check now – Zero Aug 06 '13 at 13:36
  • @Doresoom and John as I said to Lucius my result is a matrix of 8 rows and 1 column and I want to name each row..is that possible? – Chrysovalando Aug 06 '13 at 13:47