Clear Filters
Clear Filters

Variable Values Different in Workspace than when in Command Window

7 views (last 30 days)
Hi all. I have a code running that plots T and Y1. I have a check that if any of the elements in Y1 exceed 100 (that is, 100%), the code will return an error message to retry. The issue is that it seems the Y1 matrix has values greater than 100 in the workspace,
123908.819923327 126870.594792914 129848.477388450 132835.405112305 135836.898734011 138850.061274510
but the code does not return the error message. When I typed "Y1" in the command window, those same values showed up as 1.2391 1.2687 1.2985 1.3284 1.3584 1.3885 in the command window, but the corret numbers I want the code to read is from the matrix (the workspace I presume). Why are these sets of values different in the first place. Here is the part of the code where it checks if the values exceed 100:
% Check for Unrealistic Output
if any(Y1 > 100)
fprintf('Warning. Concentration Values Exceed Limit. Consider lowering leakage rate.\n')
error= msgbox('Warning. Concentration Values Exceed 100%. Consider lowering leakage rate.');
waitfor(error)
choice1 = questdlg('Would you like to start over?', ...
'Restart?', ...
'Yes','No','Yes');
switch choice1
case 'Yes'
diffusiontool
case 'No'
% clearvars -global;
% clearvars;
% close;
return
end
else
fprintf('Complete\n')
end
Note: Y1 can have a variety of inputs, as it is built from user inputs. In this case, Y1 is a 51473x50 double. Any help would be appreciated! Thank you!

Answers (1)

Jan
Jan on 8 Aug 2017
The question is not clear yet. Are your values:
Y1 = [123908.819923327, 126870.594792914, 129848.477388450, 132835.405112305, ...
135836.898734011, 138850.061274510];
or
Y1 = [1.2391 1.2687 1.2985 1.3284 1.3584 1.3885]
Perhaps you mean, that the 1st definition shows this in the command window:
format short
Y1
Y1 =
1.0e+05 *
1.2391 1.2687 1.2985 1.3284 1.3584 1.3885
But this does not mean, that the values of Y1 have been changed. The |format< command influences the output to the command window only. See:
format long g
Y1
Now you test:
if any(Y1 > 100)
disp('Any Y1 is > 100')
end
I'm sure, this works exactly as expected. If your if branch is not entered, you have another problem. Perhaps you are not calling this code, but another script with the same name in another folder? Set a breakpoint in the code and run it again. Now step through the program line by line to examine, what's going on.

Community Treasure Hunt

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

Start Hunting!