Matrix Simple Index Question

Hello Experts,
1) Given matrix A with m rows and n columns, I want to check if there is an entry A(i,j)>alpha and if yes to make it A(i,j) = beta. How to make it without for and if? 2) How to make it in a vector of size (1,m) or (1,n)?
Thanks a lot in advance!

 채택된 답변

Oleg Komarov
Oleg Komarov 2012년 6월 1일

3 개 추천

Sample inputs:
m = 10;
n = 13;
A = rand(m,n);
alpha = .38;
Use logical indexing
idx = A > alpha;
A(idx) = 10;
Same applies to a vector (just play around with m and n to see that).

댓글 수: 4

Steve
Steve 2012년 6월 1일
Dear Oleg,
Thank you very much for your quick response and smart solution!
Please provide me a link or a book name where can I find all those shortcuts and tricks.
Thanks a lot in advance.
Oleg Komarov
Oleg Komarov 2012년 6월 1일
Check out the getting started guide and especially this section: http://www.mathworks.co.uk/help/techdoc/learn_matlab/f2-8955.html
Oleg Komarov
Oleg Komarov 2012년 6월 1일
Demos are also useful: http://www.mathworks.co.uk/products/matlab/demos.html
Steve
Steve 2012년 6월 2일
Dear Oleg, again thank you very very much!!!
It was my great pleasure to get your answer and experts guide!
Steve

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

추가 답변 (0개)

카테고리

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

제품

질문:

2012년 6월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by