How do I make EXTRAPVAL a scalar?

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

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
When surf is used the first argument cannot be a scalar.
prompt='What is the front ride height?: ';
a=input(prompt,'s');
prompt='What is the rear ride height?: ';
b=input(prompt,'s');
This is the beginning of my code for my a and b variables. When I try using numbers in my Map1 definition (such as 1,2 or 1:5,2:6 as you used), I then get the error: Input grid is not a valid MESHGRID. When I change them back to a,b I again recieve the EXTRAPVAL must be a scalar error.
did you see my answer ? @Cory
@madhan ravi Surf is not where I am currently having the issue. This error occurs during the interp2 line of code and the program will not advance.
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);

Sign in to comment.

Answers (3)

madhan ravi
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)

4 Comments

Thanks so much @madhan ravi!
Anytime :)
Ok, I assumed your code would work, but I am still recieving the same error: Input grid is not a valid MESHGRID. Any more ideas?
upload your datas as .mat file to test

Sign in to comment.

Cory Runnells
Cory Runnells on 10 Dec 2018
There's bunches of garbage code at the bottom since I'm testing things. But see if you can spot the error

5 Comments

attach your excel file and remove the inputs and just fill it up with values , please make it easier for us debug
Hopefully this makes it easier
provide the input values .... a,b,c,,,etc..
a=6 b=7 c=8 d=9; really any input values are what I want to work.
ok cory , you can unaccept my answer , Star Strider is really an expert in this , he can easily debug it.

Sign in to comment.

Stephen23
Stephen23 on 10 Dec 2018
Edited: Stephen23 on 10 Dec 2018
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

Asked:

on 10 Dec 2018

Edited:

on 10 Dec 2018

Community Treasure Hunt

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

Start Hunting!