フィルターのクリア

I have been trying to read multiple ASCII files which have file names (23318.asc to 25897.asc). I doesn't seem working. This is what I have so far.

1 回表示 (過去 30 日間)
clc,
a= 23318:25897
for k= 1:length(a)
i= 23317+k;
ascFilename = ['3841' num2str(i) '.asc']
content = fscanf ('ascFilename') ;
formatSpec = ['%f%f%*f%f%*f%f', repmat('%*f', 1, 73), '%f%*[^\n]'] ;
data = textscan( content, formatSpec, 'HeaderLines', 12 ) ;
A = data{1};
B= data{2};
C = data{5};
C(C < 0) = NaN; %set negative numbers to 'empty'
length(C)
C
figure(1);
scatter(C,A); %plot first set of data
hold on;
title('Altitude vs Temperature');
ylabel('Temperature');
xlabel('Altitude');
end
  1 件のコメント
Mahdi
Mahdi 2014 年 6 月 3 日
What's the error that you're getting? Can you also please format your code by pressing the code {}Code button?

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

採用された回答

Star Strider
Star Strider 2014 年 6 月 3 日
編集済み: Star Strider 2014 年 6 月 3 日
You are not using textscan correctly.
First, you have to use fopen to open the file and create a fileID:
fidin = fopen(ascFilename, 'r'); % Open file for reading
NOTE that because ascFilename has already been created as a string variable, you do not need quotes around it in the fopen statement.
Delete the first line calling textscan. (The line creating content.) It is unnecessary in your code. It’s also wrong and won’t work anyway. It will simply throw an error and stop your code.
Then to read the file, these statements need to be in this order:
formatSpec = ['%f%f%*f%f%*f%f', repmat('%*f', 1, 73), '%f%*[^\n]'] ;
data = textscan( fidin, formatSpec, 'HeaderLines', 12 ) ;
I can’t be certain that this will work because I don’t have you data file to check it with, but it should get you started. If you wrote your formatSpec line correctly, everything you want should be in your data variable
  8 件のコメント
anton fernando
anton fernando 2014 年 6 月 3 日
Thank you very much mate. Works perfectly. you are the best.
Star Strider
Star Strider 2014 年 6 月 3 日
As always, my pleasure!
Just noticed ODU. W&L and UVA myself.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by