Borrar filtros
Borrar filtros

fopen does not work for filename given by fullfile

22 visualizaciones (últimos 30 días)
Hyon Kim
Hyon Kim el 16 de Dic. de 2016
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,

Respuesta aceptada

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

Más respuestas (1)

Kevin Daniel Resendiz Rivera
Kevin Daniel Resendiz Rivera el 26 de Abr. de 2023
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 comentarios
Steven Lord
Steven Lord el 26 de Abr. de 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
Kevin Daniel Resendiz Rivera el 26 de Abr. de 2023
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

Iniciar sesión para comentar.

Categorías

Más información sobre Low-Level File I/O en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by