フィルターのクリア

Loop to Organize Matrices

3 ビュー (過去 30 日間)
Anas Khan
Anas Khan 2020 年 11 月 26 日
編集済み: Ameer Hamza 2020 年 11 月 26 日
I want to split up a large matrix (Vdata) with 768 columns of data into 12 matrices, each with 64 columns of data. I could do this by hand and assign each matrix the correct columns, but I want this to be end-user friendly and be able to be done by just running a script. I have come up with the code below thus far. But, I can't seem to figure out how to use a third looping variable to create new matrices for example (Col1 to Col12 in steps of 1: Col1, Col2, Col3,...).
n = [64:64:768];
m = n-63;
for i = m
for j = n
Col = Vdata(:,i:j);

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 11 月 26 日
編集済み: Ameer Hamza 2020 年 11 月 26 日
Naming variables like Col1, Col2, ... is a very bad coding practice: https://www.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dynamically-eval. It is much easier to use cell arrays. For example
Vdata = rand(100, 768);
Col = mat2cell(Vdata, size(Vdata, 1), 64*ones(size(Vdata, 2)/64, 1));
Col is a cell array with each element having 64 columns.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by