フィルターのクリア

fopen does not work for filename given by fullfile

22 ビュー (過去 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 件のコメント
Hyon Kim
Hyon Kim 2016 年 12 月 16 日
ah, I see. This works. Thanks a lot!

サインインしてコメントする。

その他の回答 (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 Center および File ExchangeLow-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