Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Getting an error after rounding data.

1 回表示 (過去 30 日間)
Afzal
Afzal 2013 年 4 月 21 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I get an error saying 'Index exceeds matrix dimensions.' when I try to plot data rounded to 3 decimal places. It works fine without rounding.
filtered_hand = sprintf('%6.3f',filtered_hand)
plot3(handles.axes4, filtered_hand(index(j),1), filtered_hand(index(j),2), filtered_hand(index(j),3), 'o')
  1 件のコメント
Afzal
Afzal 2013 年 4 月 21 日
編集済み: Afzal 2013 年 4 月 21 日
I figured it out. I need to use num2str(data, precision) instead of sprintf. I actually wanted to do the following:
plot3(handles.axes4, filtered_hand(index(j),1), filtered_hand(index(j),2), filtered_hand(index(j),3), 'o')
set(handles.text1, 'String', ['The position of target ' num2str(j) ' is x = ' num2str(filtered_hand(index(j),1),3) ' m y = ' num2str(filtered_hand(index(j),2),3) ' m z = ' num2str(filtered_hand(index(j),3),3) ' m '])

回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 4 月 21 日
編集済み: Azzi Abdelmalek 2013 年 4 月 21 日
After
filtered_hand = sprintf('%6.3f',filtered_hand)
filtered_hand becomes a string
If you want to round to 3 decimals use
filtered_hand = round(filtered_hand*1000)/1000

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by