multiple area access in cells

조회 수: 3 (최근 30일)
Bass Tea
Bass Tea 2019년 1월 30일
댓글: Bass Tea 2019년 1월 30일
dear ladies and gentlemen,
i have got another question. if i have a cell of arrays, e.g. ...
>> D(:,1)
ans =
[3x3 double]
[3x3 double]
[3x3 double]
and every cell element (in this case arrays) containes double values like the first cell element does, ...
>> D{1}
ans =
0.118997681558377 0.340385726666133 0.751267059305653
0.498364051982143 0.585267750979777 0.255095115459269
0.959743958516081 0.223811939491137 0.505957051665142
what comprehensible gives same result as , ...
>> D{1,1}
well! and if have another cells of arrays, let us say e.q.: ...
A =
[3x3 double]
[3x3 double]
[3x3 double]
with arrays like this: ..
>> A{1}
ans =
6 5 2
8 1 8
9 1 2
how can i reference my cells to rewirte e.q. every element in cell D and its every first column with first column of A, and
while doing so at the best without a loop or an if.
first, i thought on the colon operator, but i cant handle it. instead of allocate cell element by element with ..
>> D{1}(:,1)=A{1}(:,1)
>> D{2}(:,1)=A{1}(:,1)
a.s.o.
i tried ...
>> D{:}(:,1)=A{1}(:,1)
and
>> D{1:3}(:,1)=A{1}(:,1)
without success.
can someone help me =) please
regards
  댓글 수: 1
madhan ravi
madhan ravi 2019년 1월 30일
attach the data as .mat file so that it's pretty clear how the cells are arranged

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

채택된 답변

Guillaume
Guillaume 2019년 1월 30일
If you want to keep your data as cell arrays you don't have a choice but to use an explicit loop:
for i = 1:numel(D)
D{i}(:, 1) = A{i}(:, 1);
end
However, since the matrices in your cell arrays are all the same size, you would be better off storing the whole lot as a 3D matrix. It's much easier to work with 3D matrices than cell arrays of 2D matrices. In particular, you could indeed do the copy in just one line
%convert cell array of 2D matrices into 3D matrix:
D = cat(3, D{:});
A = cat(3, A{:});
%replace 1st column of each page:
D(:, 1, :) = A(:, 1, :);
  댓글 수: 1
Bass Tea
Bass Tea 2019년 1월 30일
hey Guillaume,
i really thank you very much for your quick response. Both methods, those who you mentioned, impress me much. i'm liking the particular idea of "array-paper sheets", like presented right-hand sided in doc help of "cat", most of all.
have many thanks, i'm gonna' do a little trial-and-error now with that new knowledge. =)
regards
1.JPG

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by