Accessing data inside a cell array using a loop

조회 수: 2 (최근 30일)
Nikesh Maharjan
Nikesh Maharjan 2022년 10월 4일
댓글: Nikesh Maharjan 2022년 10월 5일
Here "data" is a cell array of size 48 x 1. Each position of the cell consists N X 2 size matrix. I want to access the data in cell and plot column 1 vs column 2 of matrix inside each cell as given by input. For e.g. If input Z=[1 2 5], I want to plot col1 vs col2 of data{1}, data{2} and data{5}.
```Z = input('input the test number\n ');
for ii = 1:length(N)
sigma(ii) = data{Z(ii)}(:,1);
delf(ii) = data{Z(ii)}(:,2);
hold on
print(sigma(ii),del(ii))
hold off
end
```

답변 (1개)

Angelo Yeo
Angelo Yeo 2022년 10월 4일
편집: Angelo Yeo 2022년 10월 4일
Woud this be working for you?
% Z = input('input the test number\n ');
Z=[1,2,5]; N = 10;
data = cell(48,1);
for i = 1:48
data{i} = rand(N,2);
end
for ii = 1:length(Z)
sigma(:, ii) = data{Z(ii)}(:,1);
delf(:, ii) = data{Z(ii)}(:,2);
figure;
plot([sigma(:, ii),delf(:, ii)]);
end
  댓글 수: 1
Nikesh Maharjan
Nikesh Maharjan 2022년 10월 5일
Hi, Angelo.
Thnx for the response.Really appreciate it. However I'm still getting an error message like
```Conversion to cell from double is not possible.
Error in untitled (line 8)
sigma(:, ii) = data{Z(ii)}(:,1);```.
I think there's something about converting from cell to double and vice versa that I don't understand. Would really appreciate if you helped me in this. Thank you

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

카테고리

Help CenterFile Exchange에서 Matched Filter and Ambiguity Function에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by