Error using interp1>re​shapeAndSo​rtXandV X and V must be of the same length

25 vues (au cours des 30 derniers jours)
Manthan le 19 Avr 2023
Commenté : Steven Lord le 19 Avr 2023
So i am working on development of GUI (fig attached) and here is one part of the code. I have attached the whole code here in attacchment.
I am not able to figureout the logic behind the error.
The data file (excel) behind this code is attached here.
*snipped subfunction copied from inside interp1.m included as part of MATLAB*
here is the output:
What is the meaning of X and V?
I am new to app designing.
Error using interp1>reshapeAndSortXandV (line 423)
X and V must be of the same length.
Error in interp1 (line 92)
[X,V,orig_size_v] = reshapeAndSortXandV(varargin{1},varargin{2});
  3 commentaires
Manthan le 19 Avr 2023
Here is the image file of GUI.
Walter Roberson
Walter Roberson le 19 Avr 2023
You need to locate the call to interp1 and put a breakpoint at the beginning of the line that calls interp1 and then run the code. When the debugger stops because of the breakpoint, show us the line of code it is calling, and show us size() of each of the variables it mentions in the call to interp1()

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 19 Avr 2023
For the purposes of interp1, x is the independent variable, and v is the corresponding dependant value.
For example you might have 50 times, but only have 49 acceleration readings.
The number of independent values must be the same as the number of dependent values.
  1 commentaire
Steven Lord
Steven Lord le 19 Avr 2023
As a general rule of thumb, an error message from a MathWorks function will refer to an input argument to that function by position (first argument, second argument, etc.) or by the name used in the help text and documentation for that function. In this case the documentation for the interp1 function uses x and v in the Syntax, Description, and Input Arguments sections.
And Walter is correct. There's a mismatch between the number of sample points and sample values.
x = [1 2 3 4 5];
v = [1 4 9 16 ]; % Whoops, forgot the 25
interp1(x, v, 2.5) % Will throw this error
Error using interp1>reshapeAndSortXandV
X and V must be of the same length.

Error in interp1 (line 128)
[X,V,orig_size_v] = reshapeAndSortXandV(X,V);

Connectez-vous pour commenter.


En savoir plus sur Data Import from MATLAB dans Help Center et File Exchange




Community Treasure Hunt

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

Start Hunting!

Translated by