필터 지우기
필터 지우기

fopen does not work for filename given by fullfile

조회 수: 21 (최근 30일)
Hyon Kim
Hyon Kim 2016년 12월 16일
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,

채택된 답변

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

추가 답변 (1개)

Kevin Daniel Resendiz Rivera
Kevin Daniel Resendiz Rivera 2023년 4월 26일
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
Steven Lord
Steven Lord 2023년 4월 26일
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 2023년 4월 26일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Low-Level File I/O에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by