Can someone pinpoint this error message
조회 수: 3 (최근 30일)
이전 댓글 표시
So I had this code working on my other script and I started over using a different version and now I am having issues getting the script to run. I have copied and pasted the for loop so I know its not written incorrectly and I cannot figure out why it is suddenly not working and I am hoping someone else can see the issue. the error is occuring at the FOR LOOP, right where it says
"para=eval(char(parameter(i)));"
the error is "
Error using ProjectSample2 (line 34)
Error: Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters,
or other syntax error. To construct matrices, use brackets instead of parentheses.
clear;
clc;
patm=101.325;
dry_bulbTemp=[0;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20;21;22;23;24;25;26;27;28;29;30;31;32;33;34;35;36;37;38;39;40;41;42;43;44;45;46;47;48;49;50]';
wet_bulbTemp=linspace(0,34,51);
sat_vapor_press=[0.611650000000000;0.657090000000000;0.705990000000000;0.758080000000000;0.813550000000000;0.872580000000000;0.935360000000000;1.00210000000000;1.07300000000000;1.14830000000000;1.22820000000000;1.31300000000000;1.40280000000000;1.49810000000000;1.59900000000000;1.70580000000000;1.81880000000000;1.93840000000000;2.06470000000000;2.19830000000000;2.33930000000000;2.48820000000000;2.64530000000000;2.81110000000000;2.98580000000000;3.16990000000000;3.36390000000000;3.56810000000000;3.78310000000000;4.00920000000000;4.24700000000000;4.49690000000000;4.75960000000000;5.03540000000000;5.32510000000000;5.62900000000000;5.94790000000000;6.28230000000000;6.63280000000000;7.00020000000000;7.38490000000000;7.78780000000000;8.20960000000000;8.65080000000000;9.11240000000000;9.59500000000000;10.0990000000000;10.6270000000000;11.1770000000000;11.7520000000000;12.3520000000000]';%sat vapor pressure
Relative_humidity=[100;94.961;89.629;85.168;81.123;77.453;74.120;71.088;68.328;65.813;63.517;61.419;59.499;57.740;56.125;54.641;52.608;52.014;50.849;49.771;48.772;47.843;46.978;46.172;45.418;44.712;44.049;43.426;42.839;42.284;41.759;41.261;40.787;40.337;39.906;39.495;39.101;38.723;38.36;38.010;37.673;37.347;37.032;36.727;36.431;36.144;35.865;35.593;35.328;35.070;34.817];
Enthalpy=[9.477;10.662;11.840;13.054;14.291;15.553;16.840;18.153;19.494;20.463;22.261;23.691;25.152;26.647;28.176;29.741;31.151;32.985;34.66;36.389;38.156;39.967;41.825;43.732;45.688;47.697;49.760;51.880;54.057;56.295;58.595;60.960;63.393;65.895;68.470;71.120;73.847;76.655;79.547;82.526;85.594;88.756;92.014;95.372;98.834;102.404;106.086;109.883;113.800;117.842;122.014];
Enthalpy=Enthalpy';
Relative_humidity=Relative_humidity';
Specific_Humidity=622.*sat_vapor_press./(patm-sat_vapor_press);
parameter={'Dry Bulb Temperature' 'Saturated Vapor Pressure' 'Wet Bulb Temperature' 'Specific Humidity' 'Relative Humidity' 'Enthalpy'};
disp('Please enter 1 if you want to enter Dry Bulb')
disp('Please enter 2 if you want to enter wet bulb')
choice=input(' ');
value=input('please enter the value ');
if choice==1
index=find(dry_bulbTemp==value);
else if choice==2
index=find(wet_bulbTemp==value);
end
end
disp('*************************************************')
fprintf('For %s= %f\n',char(parameter(choice)), value)
for i=1:6
if i~=choice
para=eval(char(parameter(i)));
fprintf('%s= %f\n', char(parameter(i)), para(index));
end
end
thank you!
댓글 수: 0
답변 (1개)
Walter Roberson
2019년 11월 24일
parameter={'Dry Bulb Temperature' 'Saturated Vapor Pressure' 'Wet Bulb Temperature' 'Specific Humidity' 'Relative Humidity' 'Enthalpy'};
%...
para=eval(char(parameter(i)));
parameter is a cell array of character vectors, so parameter(i) is going to be a scalar cell array of character vector, and char() of that is going to be the character vector. You could also have used parameter{i} instead of char(parameter(i)) to get that.
Suppose i is 1, so char(parameter(i)) is going to to be 'Dry Bulb Temperature'
You would then try to
eval('Dry Bulb Temperature')
That would attempt to find a function named Dry and evaluate it as if you had called
Dry('Bulb', 'Temperature')
which is probably going to fail.
Just. Don't. Do. That.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Argument Definitions에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!