hi,
I have a matrix say 200*30. I need to limit the elements of 29th and 30th columns with different constraints. how can I do that?
thanks,

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2015 年 7 月 8 日

0 投票

Example
A=rand(200,30)
idx=A(:,29)>0.5 & A(:,30)<0.7
out=A(idx,:)

4 件のコメント

mehrdad asadi
mehrdad asadi 2015 年 7 月 8 日
thanks,
but I actually need to modify the elements!
for example if A(:,30)>1, then I should replace it with 1.
is it possible not to use 'if'?
Azzi Abdelmalek
Azzi Abdelmalek 2015 年 7 月 8 日
編集済み: Azzi Abdelmalek 2015 年 7 月 8 日
You don't need a loop
idx=A(:,30)>1
A(idx,30)=1
mehrdad asadi
mehrdad asadi 2015 年 7 月 8 日
thank you A.Abdelmalek,
I did this, but because I have 4 constraints, and it should be repeated many times in a for loop, it seems it's not that much optimized! thanks anyway, right now, this is the only solution that crosses the mind.
Stephen23
Stephen23 2015 年 7 月 8 日
編集済み: Stephen23 2015 年 7 月 8 日
Azzi Abdelmalek's solution is much more optimized than using a loop. This is how MATLAB works best, using basic code vectorization and indexing.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by