How do I make EXTRAPVAL a scalar?
Afficher commentaires plus anciens
ex[Y,Z]=meshgrid(5:5:35,10:5:90);
cl=reshape(v,17,7);
cd=reshape(w,17,7);
bal=reshape(x,17,7);
Map1=interp2(cl,cd,bal,a,b);
surf(Map1,Y,Z)
v, w, and x all represent xlsreads. a and b are single numbers prompted by the user.
I am trying to graph these points on a 3d surface plot, but I always get the error using interp2: EXTRAPVAL must be a scalar. When I move certain variables around, the error then becomes: not monotonically increasing.
Please help, I can not figure this out.
6 commentaires
Stephen23
le 10 Déc 2018
I don't get any error:
>> [Y,Z] = meshgrid(5:5:35,10:5:90);
>> cl = reshape(1:17*7,17,7);
>> cd = reshape(sqrt(1:17*7),17,7);
>> bal = reshape(pow2(1:17*7),17,7);
>> Map1=interp2(cl,cd,bal,1,2)
Map1 = 16
>> Map1=interp2(cl,cd,bal,1:5,2:6)
Map1 =
16.00000 3948062.11765 1010638366.11765 NA NA
madhan ravi
le 10 Déc 2018
When surf is used the first argument cannot be a scalar.
Cory Runnells
le 10 Déc 2018
madhan ravi
le 10 Déc 2018
did you see my answer ? @Cory
Cory Runnells
le 10 Déc 2018
Steven Lord
le 10 Déc 2018
The problem with the code you posted two comments above is the 's' in your input statements. When you use 's' in input it returns what the user entered as text, not as numbers. Because of that, I believe MATLAB interprets your interp2 call as the "Vq = interp2(V, Xq, Yq, METHOD, EXTRAPVAL)" signature instead of "Vq = interp2(X, Y, V, Xq, Yq)".
Instead, have input return what the user entered as numbers.
prompt='What is the front ride height?: ';
a=input(prompt);
prompt='What is the rear ride height?: ';
b=input(prompt);
Réponses (3)
madhan ravi
le 10 Déc 2018
Modifié(e) : madhan ravi
le 10 Déc 2018
EDITED
[Y,Z]=meshgrid(5:5:35,10:5:90);
cl=reshape(v,17,7);
cd=reshape(w,17,7);
bal=reshape(x,17,7);
prompt='What is the front ride height?: ';
a=input(prompt);
prompt='What is the rear ride height?: ';
b=input(prompt);
ab=[a b];
[A,B]=meshgrid(min(ab):0.25:max(ab)); %reduce the step size if finer grid is wanted
Map1=interp2(cl,cd,bal,A,B);
surf(Map1,Y,Z)
https://in.mathworks.com/help/matlab/ref/interp2.html#btyq8s0-2_1 meshgrid should be used! before interp2
4 commentaires
Cory Runnells
le 10 Déc 2018
madhan ravi
le 10 Déc 2018
Anytime :)
Cory Runnells
le 10 Déc 2018
madhan ravi
le 10 Déc 2018
upload your datas as .mat file to test
Cory Runnells
le 10 Déc 2018
0 votes
5 commentaires
madhan ravi
le 10 Déc 2018
attach your excel file and remove the inputs and just fill it up with values , please make it easier for us debug
Cory Runnells
le 10 Déc 2018
madhan ravi
le 10 Déc 2018
provide the input values .... a,b,c,,,etc..
Cory Runnells
le 10 Déc 2018
madhan ravi
le 10 Déc 2018
ok cory , you can unaccept my answer , Star Strider is really an expert in this , he can easily debug it.
Add str2double:
a = str2double(input(prompt,'s'));
...
b = str2double(input(prompt,'s'));
This is more robust than calling input without the 's' option.
Catégories
En savoir plus sur Programming dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!