splitapply with @num2str

조회 수: 2 (최근 30일)
Kayla Black
Kayla Black 2020년 6월 3일
댓글: madhan ravi 2020년 6월 4일
I need to figure out how to set the precision of all numbers of a column in a table to 0.0 (i.e I have a value 34 that needs to output as 34.0). My professor has suggested using num2str is easier that sprintf for this matter. We have been learning about splitapply, so I thought maybe he intends for us to use that here. The table is from an excel file that I read in. Ergo, I have the following code:
table1 = table(Verb, meanEstimates);
meanEstimates = splitapply(@num2str, meanEstimates, '.1d');
I get the follow error message "Group numbers must be a vector of postitive integers, and cannot be a sparse vector."
In all honesty I don't really know what I'm doing because it's been hard to learn online this quarter.
  댓글 수: 2
madhan ravi
madhan ravi 2020년 6월 3일
It would be better if you share a short example values to experiment ;)
Kayla Black
Kayla Black 2020년 6월 3일
Ah okay, sorry, I never posted on here before so idk what I'm doing or maybe how to help you help me, but here's the table I'm working with. I just need to change 34 to 34.0 without hardcoding. Let me know if there's any more info you need from me.

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

채택된 답변

madhan ravi
madhan ravi 2020년 6월 3일
vpa(table1pretty{:,2},digits(5))
  댓글 수: 3
Kayla Black
Kayla Black 2020년 6월 4일
You helped me so much! I appreciate this, especially during a time of online learning I can use all the help I can get.
madhan ravi
madhan ravi 2020년 6월 4일
I feel it too, been there done that. Best of luck!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by