필터 지우기
필터 지우기

For loop question/ plot figure

조회 수: 1 (최근 30일)
douglas
douglas 2012년 4월 10일
  1. I am using a for loop to plot muliple text files; (files go from MT_0058 to MT_0212.txt) Which represent helicopter flight data, And I am running into an issue where some of the files (60% or more) have bad data for the first 300 rows, but may have 20-30 thousand in total. I would like to adjust the headerlines to exclude this bad data, but am running into a problem where some of the files have fewer than 300 rows (shorter flights). Is there a way to adjust the headerlines and ignore text files that have fewer than the minimum amount of rows? Without stopping the program.
  2. When plotting these text files, is there a way to simply use the saveas function without opening the plots as to avoid cluttering my computer with a large amount of open figures?
for k = 58:212
inputFileName = sprintf('MT_%05i-000.txt',k);
outputFileName = sprintf('results%05i.tiff',k);
fid = fopen(inputFileName);
datacell = textscan(fid, '%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f','HeaderLines',5);
fclose(fid);
...
saveas(gcf,outputFileName);
end

채택된 답변

Thomas
Thomas 2012년 4월 10일
If you are on a linux system try
for k = 58:212
inputFileName = sprintf('MT_%05i-000.txt',k);
outputFileName = sprintf('results%05i.tiff',k);
fid = fopen(inputFileName);
new_cmd=sprintf('more %s|wc -l', inputFileName);
[p,num_lines]=system(newcmd);
if num_lines<=300
datacell = textscan(fid, '%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f','HeaderLines',5);
fclose(fid);
else
datacell = textscan(fid, '%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f','HeaderLines',300);
fclose(fid);
...
saveas(gcf,outputFileName);
end
end
Do not have access to MATLAB currently so cannot check..
  댓글 수: 2
Thomas
Thomas 2012년 4월 11일
I guess you are on a windows platform and hence have re-posted the question..
douglas
douglas 2012년 4월 11일
yes I have, sorry for the confusion

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by