Apologies in advance if I get something wrong. This is my first post here (I'm sure there will be many to follow).
I have a file I want to load into Octave but it doesn't work. It is a plain text file (.txt). The file is homogeneous and an excerpt of a few lines from it look like this:
0023,225.935,341.770,17.658
0024,225.935,341.758,17.782
LTAX17,228.152,353.935,17.665
LTAX24,288.304,332.878,24.074
where the first column depicts the name of the point while the rest represent its 3D coordinates.
Some of the options I've tried (but not limited to these) were unsuccessful.
x=load(text.txt)
error: scalar cannot be indexed with .
error: evaluating argument list element number 1
x=load("-text", "text.txt")
warning: load: file found in load path
error: load: empty name keyword or no data found in file 'text.txt'
x=fileread(text.txt)
warning: load: file found in load path
error: load: empty name keyword or no data found in file 'text.txt'
I have also tried simplifying the file, leaving only the coordinates and treating the file as a CSV but I keep getting similar errors.
You can load your data using the "-ascii" option but you'd have to reformat your file slightly before putting it into load even with the "-ascii" option enabled. Use a consistent column separator ie. just a tab or a comma, use full numbers not 3850.
mat file you might have, or whether Octave keeps up with the latest Matlab formats. Here's a link that might be a good start. Bottom line is that you can say: load MyMatFile. mat right at the Octave prompt.
I think load
is only for data files, not for text files. You might to use csvread
, dlmread
, textscan
or textread
. Check the documentation as to the correct syntax for invoking each of these functions.
Here are the different approaches:
load
does not work as you found out
x = load('test.txt')
error: value on right hand side of assignment is undefined
csvread
works but converts all non-numeric values to 0
x = csvread('test.txt')
x =
23.00000 225.93500 341.77000 17.65800
24.00000 225.93500 341.75800 17.78200
0.00000 228.15200 353.93500 17.66500
0.00000 288.30400 332.87800 24.07400
dlmread
works in the same way as csvread
x = dlmread('test.txt')
x =
23.00000 225.93500 341.77000 17.65800
24.00000 225.93500 341.75800 17.78200
0.00000 228.15200 353.93500 17.66500
0.00000 288.30400 332.87800 24.07400
textscan
works, results are stored in a cell array
fid = fopen('test.txt');
x = textscan(fid,'%s %f %f %f','Delimiter',',')
x =
{
[1,1] =
{
[1,1] = 0023
[2,1] = 0024
[3,1] = LTAX17
[4,1] = LTAX24
}
[1,2] =
225.94
225.94
228.15
288.30
[1,3] =
341.77
341.76
353.94
332.88
[1,4] =
17.658
17.782
17.665
24.074
}
>> fclose(fid);
I haven't done textread
, but you get the idea.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With