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