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

4 次查看(过去 30 天)
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?

采纳的回答

Star Strider
Star Strider 2023-5-31
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 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by