- https://www.mathworks.com/help/stats/mvregress.html
- https://www.mathworks.com/help/matlab/ref/cell2mat.html
- https://www.mathworks.com/help/matlab/ref/double.reshape.html
Problem with mvregress when working with cell arrays
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
I have a problem when using multivariate regression function (mvregress) available in matlab. I have a cell array with 20 cells in each of which there are three values as inputs and my target output is a vector with 20 values. When I load this data and call mvregress function, it gives the error: "Undefined function 'isnan' for input arguments of type 'cell'."
To eliminate this problem I tried using: data = cellfun(@isnan,originaldata,'UniformOutput',false)
But this makes all my values zero.
My code is given below:
load mywork1.mat
[beta,Sigma, resid] = mvregress(targetvalues',originaldata)
Since it gives the error ("Undefined function 'isnan' for input arguments of type 'cell'."), I tried the following
data = cellfun(@isnan,originaldata,'UniformOutput',false)
But then all my data cells are replaced with zeros.
How can I resolve this issue and perform multivariate regression on these data? I have attached the data set. Thank you in advance.
0 comentarios
Respuestas (1)
Snehal
el 30 de En. de 2025
Hi,
I understand that you are encountering an issue with the 'mvregress' function. The error occurs because the 'mvregress' function requires inputs to be of type matrix, whereas the data type of 'originalData' is a cell array.
You can use the ‘cell2mat’ function to convert its type to matrix. The output will need to be reshaped into a matrix of compatible dimensions before it can be used in the `mvregress` function.
Regarding the issue of all data cell values replaced with zeros, when we pass the ‘isnan’ function as an input parameter to a cell function, it returns 0 (false) for each non-NaN element (indicating that no NaN values are present). Consequently, the data is replaced with zeros.
Refer the sample code below:
load mywork.mat
OriginalDataMat = cell2mat(originaldata);
OriginalDataReshaped = reshape(OriginalDataMat, 3, 20); %reshaping the matrix to dimensions same as ‘originalData’
[beta,Sigma, resid] = mvregress(targetvalues',OriginalDataReshaped')
Refer to the below documentation links for more information:
Hope this helps.
0 comentarios
Ver también
Categorías
Más información sobre Matrices and Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!