Effacer les filtres
Effacer les filtres

Why does str2double command return NaN? What type of array should I convert into for running fitlm command??

3 vues (au cours des 30 derniers jours)
Hi all,
This issue is holding me over two hours so I want to ask how to fix it.
My dataset is a 48X1 cell array, and want to run comman fitlm to derive AR(1) process - yes, it is time series data.
x =
48×1 cell array
{[ 7.9614]}
{[ 6.6333]}
{[ 6.5029]}
{[ 5.9425]}
{[ 1.8100]}
{[ -0.4337]}
{[ -2.9584]}
{[ -1.9444]}
{[ -0.9811]}
{[ -1.2110]}
{[ 0.0166]}
{[ -0.7115]}
{[ -1.4040]}
{[ 1.0919]}
{[ 1.8558]}
{[ 11.2266]}
{[ 0.3792]}
{[ -1.9763]}
{[ -4.0722]}
{[-16.7206]}
{[ -6.4143]}
{[ -5.3453]}
{[ -2.5355]}
{[ 1.8669]}
{[ 3.4383]}
{[ 5.9412]}
{[ 5.4722]}
{[ 11.5480]}
{[ 6.3237]}
{[ 5.7294]}
{[ 4.7529]}
{[ 4.0313]}
{[ 3.4431]}
{[ 1.5301]}
{[ -0.4894]}
{[ -7.7308]}
{[ -3.1757]}
{[ -8.3770]}
{[ -1.9913]}
{[ 0.7572]}
{[ 7.9531]}
{[ 16.1144]}
{[ 14.1777]}
{[ 13.6904]}
{[ 9.4649]}
{[ 9.7910]}
{[ 5.4224]}
{[ 1.8821]}
I want to conert the dataset x to run a regression but don't know which type of data I should convert to. In the first place, I tried str2double but it returned only 48 NaNs. I tried to cell2mat but it didn't work either. What command should I use for running fitlm?

Réponse acceptée

Star Strider
Star Strider le 31 Mai 2023
Of course str2double returned NaN for all of them because none of them are strings or character vectors.
I suspect there are concatenation brackets missing. That aside, the easiest way to do what you want is to use cell2mat
x = [{[ 7.9614]}
{[ 6.6333]}
{[ 6.5029]}
{[ 5.9425]}
{[ 1.8100]}
{[ -0.4337]}
{[ -2.9584]}
{[ -1.9444]}
{[ -0.9811]}
{[ -1.2110]}
{[ 0.0166]}
{[ -0.7115]}
{[ -1.4040]}
{[ 1.0919]}
{[ 1.8558]}
{[ 11.2266]}
{[ 0.3792]}
{[ -1.9763]}
{[ -4.0722]}
{[-16.7206]}
{[ -6.4143]}
{[ -5.3453]}
{[ -2.5355]}
{[ 1.8669]}
{[ 3.4383]}
{[ 5.9412]}
{[ 5.4722]}
{[ 11.5480]}
{[ 6.3237]}
{[ 5.7294]}
{[ 4.7529]}
{[ 4.0313]}
{[ 3.4431]}
{[ 1.5301]}
{[ -0.4894]}
{[ -7.7308]}
{[ -3.1757]}
{[ -8.3770]}
{[ -1.9913]}
{[ 0.7572]}
{[ 7.9531]}
{[ 16.1144]}
{[ 14.1777]}
{[ 13.6904]}
{[ 9.4649]}
{[ 9.7910]}
{[ 5.4224]}
{[ 1.8821]}]
x = 48×1 cell array
{[ 7.9614]} {[ 6.6333]} {[ 6.5029]} {[ 5.9425]} {[ 1.8100]} {[-0.4337]} {[-2.9584]} {[-1.9444]} {[-0.9811]} {[-1.2110]} {[ 0.0166]} {[-0.7115]} {[-1.4040]} {[ 1.0919]} {[ 1.8558]} {[11.2266]}
xv = cell2mat(x)
xv = 48×1
7.9614 6.6333 6.5029 5.9425 1.8100 -0.4337 -2.9584 -1.9444 -0.9811 -1.2110
xv = [x{:}].' % Alternative Approach
xv = 48×1
7.9614 6.6333 6.5029 5.9425 1.8100 -0.4337 -2.9584 -1.9444 -0.9811 -1.2110
See if that works in your application.
.
  4 commentaires

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by