Import a specific structure with numbers in MATLAB

Hi!
I have txt file with numbers. This numbers are given inside the specific form. Example: XY={{0.3`,0.38237129451839642`},{0.4`,0.43291827234382921`}{0.5`,0.34291723195213023`}};
I would like to import this numbers in MATLAB workspace and get something like this: a=[0.3, 0.4, 0.5]; b=[0.38237129451839642, 0.43291827234382921,0.34291723195213023];
Keep the number of decimal places is necessary.
What is the best way to achieve this? Thank you!

1 个评论

@Dejan Hrovatin: please edit your question and upload a sample file by clicking the paperclip button.

请先登录,再进行评论。

 采纳的回答

Read the file into a string using fileread, and then try this:
>> str = 'XY={{0.3`,0.38237129451839642`},{0.4`,0.43291827234382921`}{0.5`,0.34291723195213023`}};'
>> vec = sscanf(str,'%*[ -/:-}]%f');
>> a = vec(1:2:end)
a =
0.3
0.4
0.5
>> b = vec(2:2:end)
b =
0.382371294518396
0.432918272343829
0.342917231952130

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by