Hello,
I have a file which contatins strings. there are 5 rows, in each one there are 4 strings separated by a comma. I'm using Matlab R2019b. I want to save those string into 5x4 matrix.
I've tried running the following code:
fpath_audio = importdata('audioPaths.txt',',');
fpath_audio(1,1)
fpath_audio(2,1)
fpath_audio_split = zeros(5,4);
for i = 1:5
fpath_audio_split(i) = strsplit(string(fpath_audio(i,1)),',');
end
But I get this error:
Unable to perform assignment because the left and right sides have a different number of elements.
Error in dpath (line 7)
fpath_audio_split(i) = strsplit(string(fpath_audio(i,1)),',');
What could be the problem? fpath_audio_split is 5x4 matrix, it should have enough space.
Thank you.

 채택된 답변

KSSV
KSSV 2020년 9월 2일

1 개 추천

fpath_audio_split = cell(5,1) ;
for i = 1:5
fpath_audio_split{i} = strsplit(string(fpath_audio(i,1)),',');
end

댓글 수: 6

Thank you very much for your answer! How can I access the strings now? when I try to print
fpath_audio_split(3,1)
for example, I get this:
ans =
1×1 cell array
{1×4 string}
How can I access the separated strings?
fpath_audio_split is now a cell array. You have to access them using flower braces, {}.
fpath_audio_split{1}
fpath_audio_split{3}
fpath_audio_split{5}
OP commented:
thank you for your answer. Is there any way to print the strings seperatly? when I print fpath_audio_split{1} I get this:
ans =
1×4 string array
"'results/priority1/inpu…" "'results/priority1/inpu…" "'results/priority1/inpu…" "'results/priority1/inpu…"
when what I want is this:
'results/priority1/inpu…'
fpath_audio_split{1}{1}
fpath_audio_split{1}{2}
Elinor Ginzburg
Elinor Ginzburg 2020년 9월 2일
thank you very much!
KSSV
KSSV 2020년 9월 2일
Thanks is accepting/ voting the answer... :)

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품

릴리스

R2019b

질문:

2020년 9월 2일

댓글:

2020년 9월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by