import strings from file to matrix

3 views (last 30 days)
Elinor Ginzburg
Elinor Ginzburg on 2 Sep 2020
Commented: KSSV on 2 Sep 2020
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.

Accepted Answer

KSSV
KSSV on 2 Sep 2020
fpath_audio_split = cell(5,1) ;
for i = 1:5
fpath_audio_split{i} = strsplit(string(fpath_audio(i,1)),',');
end
  6 Comments
KSSV
KSSV on 2 Sep 2020
Thanks is accepting/ voting the answer... :)

Sign in to comment.

More Answers (0)

Categories

Find more on Characters and Strings in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!