0
我有一個主要代碼和一個從.dat文件導入數據的函數,我想導入很多情況,因此我創建了幾個目錄來構造文件。Matlab fopen變量路徑
下面是函數的相關部分我使用:
function [time_,cm,cd_,cl,clf1,clr] = importcd2(filename, startRow, endRow)
formatSpec = '%7s%33s%24s%24s%24s%s%[^\n\r]';
%% Open the text file.
fileID = fopen(filename,'r');
textscan(fileID, '%[^\n\r]', startRow(1)-1, 'ReturnOnError', false);
然後,當我想從主代碼調用的函數,我用:
[a,~,b,~,~,~] = importvar('/folder1/folder2/folder3/folder4/folder5/file1.dat', 1, inf);
在其中a和b是我想要從.dat文件導出的變量。我想要做的是改變函數,這樣fopen可以打開一個完整的路徑,而不僅僅是文件的ID(file1.dat),因爲我更喜歡有一些目錄而不是30 .dat文件或更多相同的目錄。可能嗎?我的問題不同於How can I load 100 files with similar names and/or string in just one step in MATLAB?
在此先感謝!
的可能重複[我怎樣才能加載100個文件具有類似名稱和/或字符串在MATLAB只是一個步驟?](http://stackoverflow.com/questions/15366374/how-can-i-load-100-files-with-similar-names-and-or-string-in- just-one-in-in-ma) – GameOfThrows
formatSpec定義了什麼? –
@MatthiasW。它由MATLAB自動定義,以根據.dat文件的格式提取值 –