フィルターのクリア

Applying an integer to a specific cell of a matrix

2 ビュー (過去 30 日間)
Noah Reilly
Noah Reilly 2021 年 2 月 2 日
コメント済み: Stephen23 2021 年 2 月 10 日
I need to apply a single integer across a group of cells in a matrix. I honestly have no idea how to do this. Here's the code that im working with right now
x = [0:0.1:3];
y = [-2:0.13:2];
Load = 0;
for (x = 1:31)
for (y = 1:31)
Load(x,0) = 10;
end
end
But that and several other variations i've tried are not working whatsover.
The Integer "Load" needs to be inserted into all values of x where y = 0.
How can I do this?
  4 件のコメント
DEEPAK Chekuri
DEEPAK Chekuri 2021 年 2 月 3 日
In this case 'y' will never be zero.
however if you have ,another list of y(which has zeros) ,then try this
for i=1:31
if y[i]==0
x[i]=Load;
end
end
Stephen23
Stephen23 2021 年 2 月 3 日
@DEEPAK Chekuri: that is not valid MATLAB code. You seem to be mixing up languages.

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

回答 (1 件)

Pratyush Roy
Pratyush Roy 2021 年 2 月 10 日
編集済み: Pratyush Roy 2021 年 2 月 10 日
Hi Noah,
The following code might be helpful :
x = 0:0.1:3;
y = -2:0.13:2;
Load = 10;%Integer that we want the elements to replace with
for i = 1:31
if y(i)==0;
x(i)=Load;
end
end
Hope this helps!
Regards,
Pratyush.
  2 件のコメント
Walter Roberson
Walter Roberson 2021 年 2 月 10 日
x(y==0)=Load;
No loop needed
Stephen23
Stephen23 2021 年 2 月 10 日
"The following code might be helpful "
Even more helpful would be to read this comment from one week ago:

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

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by