IMPORTDATA方法
對於電池陣列的輸出,你可以使用這個 -
a1 = importdata(filepath,'%s') %//' filepath is the path to your text file
s1 = regexp(a1,'\s','Split')
out = cellfun(@(x) x(:,2), s1(2:end)) %// expected output as a cell array
如果你想有一個雙陣列作爲輸出,使用上面的代碼後 -
out = str2double(out)
Textscan方法
fid = fopen(filepath,'r'); %//' filepath is the path to your text file
d1 = textscan(fid,'%s %f %s','HeaderLines',1);
out = d1{1,2} %// out is expected output as a double array
fclose(fid);
編輯1:
a1 = importdata(filepath,'%s') %//' filepath is the path to your text file
s1 = regexp(a1,'\s','Split')
s1 = s1(cellfun(@numel,s1)>1) %//' removes rows like `---` or empty lines
out = cellfun(@(x) x(:,2), s1(2:end))
out = str2double(out);
out = out(~isnan(out)) %// expected output as a double array
與我們分享您的輸入數據的一些示例,從而給我們的想法有關使用的分隔符(一個或多個),如果可能的預期產出也是如此。 – Divakar
謝謝。完成... – Baloo
你在尋找一個結構輸出嗎? – Divakar