Clear Filters
Clear Filters

fopen does not work for filename given by fullfile

22 views (last 30 days)
Hi
I tried to read input data from a file as follows. However it returns an error such that; "Error using fopen First input must be a file name of type char, or a file identifier of type double."
main_data_path ='/usr/local/MATLAB/......';
folder = fullfile(main_data_path, 'row_data',...
{'data1.dat';...
'data2.dat';...
'data3.dat';...
'data3.dat';});
disp(folder);
data1 = folder(1,1);
fileID = fopen(data1);
Can anyone please let me know what is wrong in this code?
Thanks you so much in advance! Best,

Accepted Answer

KSSV
KSSV on 16 Dec 2016
Try
fileID = fopen(data1{1})
Instead of
fileID = fopen(data1);
fopen needs a filepath as a character, your data1 is a cell.

More Answers (1)

Kevin Daniel Resendiz Rivera
hi, i have a this problem
s = serialport("COM3",9600); % Abre el puerto serie
fopen(s); % Abre la conexión
figure; % Crea la figura
plot(0,0); % Crea la línea inicial
while ishandle(1) % Bucle hasta que se cierre la figura
data = fscanf(s,"%f"); % Lee la temperatura del puerto serie
x = get(gca,"XLim").*[1 1]; % Obtiene los límites actuales del eje X
y = [get(gca,"YLim");data data]; % Añade la temperatura a los datos
set(1,"XData",x,"YData",y); % Actualiza la figura
drawnow; % Redibuja la figura
end
fclose(s); % Cierra la conexión
Error using fopen
First input must be a file name or a file identifier.
Error in mezfinal (line 2)
fopen(s); % Abre la conexión
  2 Comments
Steven Lord
Steven Lord on 26 Apr 2023
There's no fopen object function listed on the serialport object's documentation page. Creating the object should open the port without need to call fopen or open or the like.
Is there something on a documentation page that led you to believe you needed to open the object before using it?
Kevin Daniel Resendiz Rivera
Hello, thank you for answering
So I delete the fopen or what would be the solution?
What I'm trying to do is send data from a sensor from the Arduino for matlab to graify it
This is the arduino code: #include SPI.h #include max6675.h
const int thermoDO = 12; const int thermoCS = 11; const int thermoCLK = 13;
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
void setup() { Serial.begin(9600); // Inicia el puerto serie }
void loop() { double celsius = thermocouple.readCelsius(); // Lee la temperatura del MAX6675 Serial.println(celsius); // Envía la temperatura al ordenador delay(1000); // Espera un segundo }
And the one above is all the matlab code.
I would like you to help me since I'm new to matlab, thank you

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!