error using num2str

조회 수: 3 (최근 30일)
yue li
yue li 2018년 9월 6일
댓글: Alamgir M S M 2019년 6월 11일
Hello, I try to use gscatters to draw the pca plot.
>> a=randn(10)
a =
0.1380 1.1569 -0.1609 0.3105 0.5558 0.4394 -0.8964 -1.0145 0.8531 -0.4698
-0.7107 0.0530 0.4093 -0.2495 -1.1203 -0.0896 -1.2033 -0.2133 0.4043 0.8864
0.7770 -1.2884 -0.9526 0.5037 -1.5327 1.0212 1.0378 -0.3253 -0.7006 -1.3852
0.6224 -0.3712 0.3173 -0.8927 -1.0979 -0.8740 -0.8459 1.9444 -1.6305 -1.9568
0.6474 -0.7578 0.0780 1.9085 -1.4158 0.4147 -0.1729 -0.5718 1.4600 0.4207
-0.4256 -0.5640 1.3244 0.1222 0.0596 0.3484 -1.2087 -0.2500 2.0500 0.4007
1.0486 0.5551 -0.2132 1.0470 -0.4113 0.3493 -0.2971 -1.5693 0.1205 0.0951
0.6607 -0.5568 -0.1345 -0.2269 -0.3680 -0.7292 -3.2320 -0.4774 -0.9899 0.4967
2.5088 -0.8951 -1.1714 -0.1625 -1.3610 0.3268 -1.0870 -1.3380 1.1978 1.0822
1.0635 -0.4093 -1.3853 0.6901 0.7796 -0.5149 -1.4264 0.0303 -0.5927 0.9704
>> [~, scores,pcvars]=pca(a)
scores =
0.7231 -0.4236 -0.8435 1.6875 -0.6992 0.2655 -0.0274 -0.0061 -0.3268
0.1185 -0.8979 -1.0235 -0.6050 -0.0047 -0.8379 -0.6529 0.6096 -0.0189
-0.9948 2.9174 0.1385 0.0806 0.1037 -0.2427 -0.5801 -0.5163 -0.0227
-3.8238 0.2561 -0.6242 -0.3132 -0.2561 0.4312 0.4093 0.3275 0.0336
1.5496 1.1953 -0.4926 -0.6628 0.9139 -0.1605 0.7067 0.1346 -0.2196
1.2263 -0.9438 -2.0018 -0.6615 0.0639 0.6865 -0.1349 -0.4513 0.2163
0.9502 0.5985 0.2710 1.1530 -0.2914 -0.5412 0.4474 0.1301 0.3926
-0.9756 -2.1818 1.0927 -0.3772 -0.0722 -0.6675 0.2564 -0.6411 -0.0881
1.4738 0.4494 1.9580 -1.1421 -0.9287 0.4928 -0.0722 0.2144 -0.0180
-0.2473 -0.9696 1.5253 0.8409 1.1708 0.5739 -0.3524 0.1987 0.0517
pcvars =
2.6823
2.0158
1.5384
0.8532
0.4142
0.3139
0.2049
0.1645
0.0410
>> x=zscore(scores(:,1));
>> y=zscore(scores(:,2));
>> z=zscore(scores(:,3));
>> gscatter3(x,y,z,tmp1,{'b','g','m'},{'.','.','.'},15)
Error using num2str (line 45)
Input to num2str must be numeric.
Error in gscatter3 (line 103)
g=cellstr(num2str(g'))';
  댓글 수: 7
Walter Roberson
Walter Roberson 2018년 9월 6일
There appear to be two gscatter3() in the file exchange: which of the two are you using? Are you using https://www.mathworks.com/matlabcentral/fileexchange/37970-gscatter3 by Salai Selvam V labeled version 1.0.0.0, or are you using https://www.mathworks.com/matlabcentral/fileexchange/61502-gscatter3 by Gustavo Ferraz Trindade labeled version 1.1.0.0, or are you using something else?
yue li
yue li 2018년 9월 6일
편집: yue li 2018년 9월 6일
Hello, Walter Roberson,
Thank you for your response.
I was use the first one. But still the same mistake.
Thank you again!

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2018년 9월 6일
For that version of gscatter3:
gscatter3(x,y,z,cellstr(tmp1),{'b','g','m'},{'.','.','.'},15)
You cannot pass that routine a cell array of string variables, but you can pass it a cell row vector of character vectors.
  댓글 수: 2
yue li
yue li 2018년 9월 7일
Hello, Walter Roberson,
Thank you so much for your great help!
Actually, I spent the whole day.
Thank you again!
Yue Li
Alamgir M S M
Alamgir M S M 2019년 6월 11일
Hi,
I did exactly the same in my code. But, it says:
"If clr is a cell array of strings, the length of clr must be equal to the length of x, y and z."
I don't know what to do. Any help please?
Sorry for asking simple question :(

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dimensionality Reduction and Feature Extraction에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by