Problem with mvregress when working with cell arrays

2 visualizaciones (últimos 30 días)
lexi11
lexi11 el 18 de Abr. de 2017
Respondida: Snehal el 30 de En. de 2025
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.

Respuestas (1)

Snehal
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')
beta = 1×3
5.3030 5.1105 4.7258
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Sigma = 3×3
1.0e+04 * 0.9093 0.7378 0.5582 0.7378 1.1819 0.8587 0.5582 0.8587 0.9888
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
resid = 20×3
36.6095 96.3414 20.3019 -148.5598 43.8379 -39.9884 -94.2007 -44.1636 -16.1113 109.7038 122.4553 156.9638 46.3092 111.3069 15.9206 105.4762 122.7648 136.2698 35.6714 49.7020 53.6868 -82.6062 -36.0759 -9.3062 106.8177 121.5931 48.9511 -124.4650 -73.3060 77.0685
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Refer to the below documentation links for more information:
Hope this helps.

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!

Translated by