フィルターのクリア

how to write a loop to read two columns for a matrix each time

3 ビュー (過去 30 日間)
xueqi
xueqi 2013 年 5 月 25 日
Hi fellows, I have a matrix called tt (50*40) and I need to read two columns from it each time. And this is my code
if true
% for i=1:20
subdata=tt(:,2i-1:2i);
end
end
but in this way I get the error message is "Subscript indices must either be real positive integers or logicals." Any one know how to solve it? Or do you have another way to read the data as I want?
Cheers

採用された回答

Image Analyst
Image Analyst 2013 年 5 月 25 日
編集済み: Image Analyst 2013 年 5 月 25 日
Try this:
% Generate some sample data:
tt = randi(3, 200, 3)
% Get pairs of adjacent, consecutive rows each iteration.
for row = 1 : 2 : size(tt)
subdata = tt(row:row+1, :)
% Now do something with subdata.
end

その他の回答 (1 件)

xueqi
xueqi 2013 年 5 月 25 日
oh right. It acutally works in this way. I was missing multiplication syntax...

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by