loading vectors with multiple dimensions from a .txt file

I have saved vectors line by line to .txt file. Now i want to load them one by one. Problem is that, vectors have different dimensions and dimensions are unknown.
The .txt file that i'm using is similar to the testing2.txt which is generated by the following code.
A = rand(28,1);
B = rand(15,1);
C = rand(36,1);
fid=fopen('testing2.txt','w');
fprintf(fid, '%f ', A);
fprintf(fid, '\n ');
fprintf(fid, '%f ', B);
fprintf(fid, '\n ');
fprintf(fid, '%f ', C);
fprintf(fid, '\n ');
fclose(fid);
Can anyone help?? Thanks in advance.

 采纳的回答

Use fgetl() to read a line into a buffer. Use sscanf() to convert the line into numeric. Store in a cell array.

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by