I have a dataset that I want to split into 24 different matrices, numbered 1 to 24 and I want to plot column 34 against column 7 of each of these matrices.
Part 1
for i = 1:1:24
group{i} = data(i:i+2,1:34)
i = i + 3
end
Part 2
for i = 1:1:24
hold on
figure
subplot(6,4,i)
scatter(group{i}(:,34),group{i}(:,7))
title (num2str(i))
xlabel('Moisture')
ylabel('Shear Strength')
end
I'm not sure where I'm going wrong. this is my first time trying for loops.

댓글 수: 1

Amelia - why are you adding three to i in your first for loop?
i = i + 3
Your code to get the group data is
group{i} = data(i:i+2,1:34)
so it looks like you are trying to extract 3x34 matrices on each iteration of your loop. If this is the case, then you may want to try
k = 1;
for i = 1:1:24
group{i} = data(k:k+2,1:34)
k = k + 3;
end
where we use k to extract the data. Note that I'm assuming that data has enough rows to extract these 24 matrices.

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

답변 (1개)

Jan
Jan 2017년 8월 30일
편집: Jan 2017년 8월 30일

0 개 추천

For the problem in Part 1 see Geoff's comment.
The part 2 creates 24 figures. Better move the figure command before the loop.
You can split the data without a loop:
dataGrouped = permute(reshape(data, 3, 24, 34), [1,3,2]);
Now dataGrouped(:, :, k) is the same as group{k}.

카테고리

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

태그

질문:

2017년 8월 30일

편집:

Jan
2017년 8월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by