Is it possible to store string arrays of variable length as different rows in csv?

조회 수: 2 (최근 30일)
Hii!
I have the following input "A" "B" "C" "D" "E" which is a 1x5 string array
and another input, say "A" "E" "1" which is a 1x3 string array
I want to open and store these in a csv file as follows
C1 C2 C3 C4 C5
R1 A B C D E
R2 A E I
Please let me know on how to proceed.
Thanks in advance!

채택된 답변

the cyclist
the cyclist 2019년 7월 23일
편집: the cyclist 2019년 7월 23일
Here is one straightforward way. It requires the cellwrite function from File Exchange.
% Original data
s1 = ["A" "B" "C" "D" "E"];
s2 = ["A" "E" "1"];
% Create a buffer of empty strings to fill the gap
s0 = ["",""];
% Combine into one string array
s = [s1; [s2,s0]];
% Write to file
cellwrite('s.csv',s)
The best way to combine the string array will largely depend on how you need this to generalize. For example, if you have a long list of string arrays, you would need to loop through them to create the buffer.
  댓글 수: 2
Sanjana Sankar
Sanjana Sankar 2019년 7월 23일
Hi!
Thanks. But MATLAB says there's no command called cellwrite.
the cyclist
the cyclist 2019년 7월 23일
Please read the second sentence of my answer more carefully.

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by