How do I make EXTRAPVAL a scalar?
Show older comments
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 Comments
Stephen23
on 10 Dec 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
on 10 Dec 2018
When surf is used the first argument cannot be a scalar.
Cory Runnells
on 10 Dec 2018
madhan ravi
on 10 Dec 2018
did you see my answer ? @Cory
Cory Runnells
on 10 Dec 2018
Steven Lord
on 10 Dec 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);
Answers (3)
madhan ravi
on 10 Dec 2018
Edited: madhan ravi
on 10 Dec 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 Comments
Cory Runnells
on 10 Dec 2018
madhan ravi
on 10 Dec 2018
Anytime :)
Cory Runnells
on 10 Dec 2018
madhan ravi
on 10 Dec 2018
upload your datas as .mat file to test
Cory Runnells
on 10 Dec 2018
0 votes
5 Comments
madhan ravi
on 10 Dec 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
on 10 Dec 2018
madhan ravi
on 10 Dec 2018
provide the input values .... a,b,c,,,etc..
Cory Runnells
on 10 Dec 2018
madhan ravi
on 10 Dec 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.
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!