How to remove a dimension from multiple arrays and store it in different cell arrays or consecutive distinct arrays

3 ビュー (過去 30 日間)
I'm trying to get 16 different times of a variable inserted into an array and then stored in different arrays. What I can do is 16 different cell arrays, but in each cell array the last loop time is repeated, ie the same time of the variable is repeated in the 16 cell arrays. The code I have is the following:
for m=1:24:361;
for p=1:n;
Mod.Var3D.P.AllNivel.Dia{p}= squeeze(Mod.Var3D.RAIZ.P(:,:,:,m));
end
end
Someone who can help me please what is the error that I am committing that I am not able to store the 16 different times of the variable in each matrix.
Regards

採用された回答

per isakson
per isakson 2017 年 10 月 6 日
編集済み: per isakson 2017 年 10 月 6 日
The major problem with your code is that Mod.Var3D.P.AllNivel.Dia{p} is overwritten for every new value of the outer loop counter, m
Here is a MWE, minimal working example, of what I believe you are looking for.
>> Dia = cssm
Dia =
[6x1 double] [6x1 double] [6x1 double]
[6x1 double] [6x1 double] [6x1 double]
[6x1 double] [6x1 double] [6x1 double]
[6x1 double] [6x1 double] [6x1 double]
[6x1 double] [6x1 double] [6x1 double]
[6x1 double] [6x1 double] [6x1 double]
where
function Dia = cssm
% Dia is short for Mod.Var3D.P.AllNivel.Dia
% P is short for Mod.Var3D.RAIZ.P
P = magic(6);
Dia = cell(0);
n = 6;
for m=1:2:6
tmp = cell( n, 1 );
for p=1:n;
tmp{p}= squeeze(P(:,m));
end
Dia = cat( 2, Dia, tmp );
end
end

その他の回答 (1 件)

Hernaldo Leyton
Hernaldo Leyton 2017 年 10 月 10 日
Thank you so much I needed, I lacked a step that was what appeared in your answer.

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by