fopen does not work for filename given by fullfile
조회 수: 22 (최근 30일)
이전 댓글 표시
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,
댓글 수: 0
채택된 답변
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
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
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
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
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 Center 및 File 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!