フィルターのクリア

How to store strings in a matrix or table?

14 ビュー (過去 30 日間)
Tmat
Tmat 2020 年 5 月 31 日
コメント済み: Tmat 2020 年 5 月 31 日
Hi, I have some strings, say, 'a1',...,'a12', and I want to store them in a 3 by 4 matrix A so that
A(1,1)='a1',..., A(1,4)='a4', A(2,1)='a5',..., A(2,4)='a8',..., A(3,1)='a9',..., A(3,12)='a12'. So that then I have a matrix A of my strings, and I can copy its content into my excel table (this is really what I want to do in the end).
However, as I try to assign string value to matrix, I recieve the following warning:
Unable to perform assignment because the indices on the left side are not compatible with the size of
the right side.
Any suggestions? Thanks in advance!

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 5 月 31 日
編集済み: Ameer Hamza 2020 年 5 月 31 日
If the end goal is to write these values in excel, the following will work (R2019a and later)
A = compose('a%d', reshape(1:12, 4, 3).');
writecell(A, 'file.xlsx')
However, in general, there is a difference in char array (single quotes) and string (double quotes) in MATLAB. So the correct syntax is
A(1,1) = "a1";
A(1,2) = "a2";
..
  1 件のコメント
Tmat
Tmat 2020 年 5 月 31 日
Thank you very much! This solved my problem!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by