assign op values from matrix

1 回表示 (過去 30 日間)
Turbulence Analysis
Turbulence Analysis 2021 年 1 月 23 日
Hi all
Is there a way to assign for loop values from the matrix
for e.g. for i = x:y, here the value of x and y needs to be assigned rom the values present in the matrix, lets say A.. Is there a way to do this ??

採用された回答

Walter Roberson
Walter Roberson 2021 年 1 月 23 日
Sure.
x = randi([0 1], 1, 50);
disp(char('0'+x))
01101000011010001111111000000111000001001001000011
locs = find(x)
locs = 1×21
2 3 5 10 11 13 17 18 19 20 21 22 23 30 31 32 38 41 44 49 50
for i = locs(13) : locs(17)-1
fprintf('x(%d) = %d\n', i, x(i));
end
x(23) = 1 x(24) = 0 x(25) = 0 x(26) = 0 x(27) = 0 x(28) = 0 x(29) = 0 x(30) = 1 x(31) = 1 x(32) = 1 x(33) = 0 x(34) = 0 x(35) = 0 x(36) = 0 x(37) = 0
  5 件のコメント
Walter Roberson
Walter Roberson 2021 年 1 月 23 日
A = [10:19, 120:150, 238:247];
mask = diff(A) == 1;
starts = A(strfind([0 mask], [0 1]));
for sequence = 1 : length(starts)
for i = starts(sequence)-5:starts(sequence)+5
do some calculations
end
filename = sprintf('results_%03d.mat', sequence);
save(filename, 'AppropriateVariable')
end
Turbulence Analysis
Turbulence Analysis 2021 年 1 月 23 日
Thanks a lot Walter.. It's serving the purpose perfectly

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by