Interpolation values from a table
Mostra commenti meno recenti
Hi guys, i wonder if anyone can help me! Im trying to intepolate values from a table that i load on to matlab but i dont understand what is the thing that i am doing wrong, can someone help me? Here is my code:



I didnt put the whole code on here because i dont think it is necessary! Basically i got the areatemp1 file with has values for areas mach and temperatures and i want to interpolate to get a mach value after calculating a Area value. if anyone could help me, it would be great
4 Commenti
the cyclist
il 9 Set 2019
If you upload your actual code, instead of an image of your code, it is vastly easier for people to help you.
Tomás Costa
il 9 Set 2019
Dheeraj Singh
il 12 Set 2019
Please check the variable type of T.Area . You can print the variable to see if it is of expected type or not. You can refer to the documentation of interp1 to see the expected type of T.Area.
Hope this helps.
Tomás Costa
il 12 Set 2019
Risposte (1)
If T.area is a cell array, and maybe T.Mach is also a cell array you must first turn them into ordinary MATLAB vectors, (n by 1 or 1 by n arrays) before interpolating. So, for example you could do something like
area = cell2mat(T.Area)
Mach = cell2mat(T.mach)
machs = interp1(area,mach,dif);
or perhaps more compactly
machs = interp1(cell2mat(T.area),cell2mat(T.mach),dif)
6 Commenti
Tomás Costa
il 12 Set 2019
Jon
il 12 Set 2019
What line in your code is the error being thrown from. Please copy and paste the whole error message, especially the part where it reprints the actual call to interp1
Tomás Costa
il 13 Set 2019
It seems that somehow your arguments aren't really what you think they are.
interp1 expects three input arguments, and looking at the code superficially, it looks like you are supplying it with 3 input arguments, so it is not obvious what the error is. Somehow, one of the three arguments you are supplying must not be evaluating to just a vector. I would suggest stepping through the code with the debugger and checking to see what those arguments evaluate to just before the function is called. Put a breakpoint on the line that generates the error. See https://www.mathworks.com/help/matlab/matlab_prog/debugging-process-and-features.html and then look in the workspace window to see what T.Area, T.Mach, and dif really are at that point. If those are as expected, e.g. cell array 31 by 1 as for T.Area, then type on the command line cell2mat(T.Area) and see what that returns (should return a vector), repeat for cell2mat(T.Mach), and then just type dif to see what that gives. Hopefully you can figure out which of those arguments is somehow not a vector and fix it from there.
If you don't want to use the debugger (although it really is the best way to debug things) you can insert the lines to just before the call to interp1 that throws the error, as earlier suggested by @Dheeraj. Note no semicolon so output will print to you command window.
T.Area
T.Mach
diff
cell2mat(T.Area)
cell2mat(T.Mach)
Jon
il 17 Set 2019
Did this answer your question? In the end what was causing the wrong number of arguments error?
Andrea
il 5 Dic 2024
I can't speak for Tomas, but Jon your answer helped a lot! Thank you.
Categorie
Scopri di più su Tables in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!