Calculating values from string and displaying?

조회 수: 5 (최근 30일)
DocD
DocD 2017년 11월 3일
댓글: DocD 2017년 11월 3일
I'm trying to perform a calculation on two values that basically takes the second x, y value in the array "EasyPracNumbers" and multiplies it by 1 to output 2 but instead it outputs:
1
2
3
This is the code:
EasyPracNumbers = [1 1; 2 2; 3 3];
CalcOutput = EasyPracNumbers(:,2)*1;
disp(CalcOutput);
What am i doing wrong, I need to use the function "hypot" on particular numbers in an array and output them to screen also, how would I do this?
  댓글 수: 1
M
M 2017년 11월 3일
>> EasyPracNumbers = [1 1; 2 2; 3 3]
EasyPracNumbers =
1 1
2 2
3 3
and then you do :
CalcOutput = EasyPracNumbers(:,2)*1
it means that you multiply the second column of EasyPracNumbers by one, so yes, it will display [1 2 3]'

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

채택된 답변

KL
KL 2017년 11월 3일
편집: KL 2017년 11월 3일
when you write
EasyPracNumbers(:,2)
you are accessing the second column. and that's why you get 3 elements. Perhaps you mean
EasyPracNumbers(2,:) %here 2 is the row number, change it to 1 or 3 as
%you wish
but still i'm not getting what you're trying to do. As far as hypotenuse goes, you might want
hypot(EasyPracNumbers(1,1),EasyPracNumbers(1,2))

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by