Filter löschen
Filter löschen

Function input as a string

1 Ansicht (letzte 30 Tage)
Adrian
Adrian am 11 Apr. 2016
Kommentiert: Adrian am 12 Apr. 2016
Hi, I want to input a filename which is a string (filename = 'exceldata.xlsx') to the input of a function. Inside the function I would like to importdata with designated filename. The function is not processing the filename as 'exceldata.xlsx'
Example Code
filename = 'exceldata.xlsx;
function [a b] = readexcel (filename)
A = importdata(filename);

Antworten (1)

Adam
Adam am 11 Apr. 2016
If you just give a filename with no path the file must be on your path. Generally you should give a full path to the file to be more robust.
You need to give more information than "is not processing" though. If you have an error message then post it in full, or give full details of whatever the problem is you get if it isn't an error.
  3 Kommentare
Jan
Jan am 11 Apr. 2016
@Adrian: As Adam has mentioned already, the error message means, that the file is not existing in the current folder. So add the folder excplicitly:
Folder = '???'
Filename = 'Matlab_Decrement_Data_415V_50H.xlsx';
File = fullfile(Folder, Filename);
and deliver File instead of Filename.
Adrian
Adrian am 12 Apr. 2016
Thank you Jan, the fullfile worked :-)

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Low-Level File I/O finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by