0

I am trying to read this text file.

Stator  M_19
Rotor   M_19
Magnet  n30h20

The text of interest is M_19 M_19 and n30h20. They are filenames of material files that will be read later.

Here is the Octave code that I tried.

clc; clear; close all;

% File path to the .csv file
filename = 'input_filenames.txt';

% Open the file
fid = fopen(filename);

% Read the first three rows of the file
formatSpec = '%s';
material_files = textscan(fid, formatSpec, 3, 2);

% Close the file
fclose(fid);

% Print the material filenames
disp(material_files);

Here is the error code I get.

error: textscan: 1 parameters given, but only 0 values error: called from test at line 11 column 16

Byte Ninja
  • 881
  • 5
  • 13
emfields
  • 1
  • 1
  • 1
    Does this answer your question? [using textscan to read badly formatted CSV file in Octave](https://stackoverflow.com/questions/62878738/using-textscan-to-read-badly-formatted-csv-file-in-octave) – Tasos Papastylianou Jul 21 '23 at 07:24
  • 1
    Use `csv2cell` from the `io` package instead. https://stackoverflow.com/a/62885690/4183191 . If your use-case is more complicated and you need further help on how to use this, search my profile fro csv2cell and you'll find several examples. Having said that, your use case seems like a simple `MyCellVariable = csv2cell( "myfile.csv", " " )` case (the second argument of an empty 'space' character denotes that your delimiter will be space). Note: if your filenames contain spaces, you may prefer to obtain lines and use `strsplit` instead. Search my profile for `strsplit` or `strtok` for exampes. – Tasos Papastylianou Jul 21 '23 at 07:25

0 Answers0