storing excel data in matrix using for loop

4 ビュー (過去 30 日間)
Davindra Usov
Davindra Usov 2022 年 5 月 16 日
コメント済み: Davindra Usov 2022 年 6 月 20 日
Hi,
I have a 4x20 matrix, A, that I have first initialised using zeros(4,20). For each row in this matrix, I want to store a 1x20 vector of data from excel. The values in these 1x20 vectors differ for each of the 4 rows (for each row, a 1x20 vector is exported from a different excel sheet). This is what I have tried so far but it is not working, as I get the error: "Unable to perform assignment because the left and right sides have a different number of elements.":
A=zeros(4,20);
n=4;
for y=1:n
A(y)=readmatrix('filename', 'Sheet', ['sheetname_' num2str(y)], 'Range', 'C5:V5');
end
Thank you

採用された回答

Stephen23
Stephen23 2022 年 5 月 16 日
編集済み: Stephen23 2022 年 5 月 16 日
n = 4;
A = zeros(n,20);
F = 'filename.xyz';
for y = 1:n
S = sprintf('sheetname_%d',y);
A(y,:) = readmatrix(F, 'Sheet', S, 'Range', 'C5:V5');
end % ^^ indexing
  1 件のコメント
Davindra Usov
Davindra Usov 2022 年 6 月 20 日
Thank you!!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by