MATLAB: Importdata not importing as a cell array and instead as a column vector

data importimportdataMATLAB

Hi,
I have this input file as a .txt here
2
0.0 1.0 6.283185307
0.0 -1.0 -6.283185307
But when I use importdata, it gives me a line vector as stated:
data =
2.0000
0
1.0000
6.2832
0
-1.0000
-6.2832
I reckon it is due to the first line of the .txt file being a single integer. I can't change the contents of the .txt file.
Any idea how to fix this?

Best Answer

You can use textscan function to read data from an open text file into a cell array.
f=fopen(‘a.txt’);
data=textscan(f,'%f%f%f',2)
Hope this helps!