Hi everyones,
I explain my question with an example :
q2 is obtained from an equation
A=[r1 r2 r3;q1 q2 q3;k1 k2 k3];
I want to select proportional row values (r2 and k2).
what should I do?
Thanks.

 채택된 답변

Star Strider
Star Strider 2015년 11월 23일

0 개 추천

Another way, especially if you don’t know where ‘r2’ is in the matrix, regardless of how large the matrix is:
A = [1:3; 4:6; 7:9];
r2 = 5;
[r,c] = find(A == r2);
other_values = setdiff([1:size(A,1)],r);
Result = A(other_values,c)
Result =
2
8

댓글 수: 4

Hamid
Hamid 2015년 11월 23일
this is good way, thanks.
because of matrix size in my code I'm gonna use an excel file instead of writing matrix.
what do you recommend?
Star Strider
Star Strider 2015년 11월 23일
My pleasure.
My code will only work for a matrix in your MATLAB workspace. It will not work for Excel files. You would have to read the matrix into your workspace with the xlsread function first.
Hamid
Hamid 2015년 11월 23일
OK Thanks very much
Star Strider
Star Strider 2015년 11월 23일
My pleasure.

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

추가 답변 (1개)

the cyclist
the cyclist 2015년 11월 23일

0 개 추천

Here's one way:
idx = A(2,:)==q2;
values = A([1 3],idx);

댓글 수: 3

Hamid
Hamid 2015년 11월 23일
this is right but here is my real problem :
I don't know which q will be obtain and it's dependent on some equations.
after that I want chosen r and k individually.
thanks.
the cyclist
the cyclist 2015년 11월 23일
Maybe Star Strider's answer works for you? If not, then I would say you should start over with a new question, and fully specify the general problem.
Hamid
Hamid 2015년 11월 23일
OK thanks

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

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

태그

질문:

2015년 11월 23일

댓글:

2015년 11월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by