我試圖讀取文件使用包含以下行替換線conatining使用textscan在MATLAB楠
1.0 2.0 3.0 textscan特殊字符? 6.0 5.0
11.0 12.0 13.0 15.0 16.0 15.0
21.0 22.0 23.0 25.0 26.0 25.0
31.0 32.0 33.0? 36.0 35.0
如何用nan替換問號?
我試圖讀取文件使用包含以下行替換線conatining使用textscan在MATLAB楠
1.0 2.0 3.0 textscan特殊字符? 6.0 5.0
11.0 12.0 13.0 15.0 16.0 15.0
21.0 22.0 23.0 25.0 26.0 25.0
31.0 32.0 33.0? 36.0 35.0
如何用nan替換問號?
你嘗試過做textscan
與%s %s %s %s %s %s
和使用str2double
所得到的單元陣列,以數字
f = fopen('file.txt');
raw = textscan(f, '%s %s %s %s %s %s');
data = [];
for k = 1:6
data = [data str2double(raw{k})];
end
您可以使用TEXTSCAN並指定「TreatAsEmpty」轉換爲「?」。
是的,它遇到'?'後停止閱讀。 – Rachel
它不應該停止閱讀,因爲'?'是一個有效的字符串,即%s。我在一個代碼示例中編輯。 – prgao
但我想用問號替換爲 – Rachel