Code Not working...sort of

조회 수: 2 (최근 30일)
C G
C G 2018년 8월 6일
편집: C G 2018년 8월 10일
I have a very long script that works, but not all the way through. When I run the non working part on its own, it works just fine. I have no idea what is going on and why it doesn't work when I press run, but works when I copy and paste the script into the command window. I don't get any errors. I just don't get the plot that I want, which is a change of atmospheric pressure over time. I tried setting the xlimits, but it doesn't let me in a scatter plot. It would also be a high inconvenience as I need to run the script for multiple months over multiple years.
I have attached my script as it is rather long and an example of the type of files I am working with. There are several hundred thousand that will need to be processed. In the script they are not text files, but I needed to make it one to attach it here.
I have also attached two image files, one showing the incorrect graph in the last subplot and the other showing the correct graph.
If anyone can help me to figure out what is going on, I would appreciate it. I am still new to matlab and I am not completely versed in why the graph is created incorrectly when I press Run, but not when I copy and paste it into the command window.
  댓글 수: 24
dpb
dpb 2018년 8월 10일
A. OK that 'splains the file naming. The % while unorthodox may not be a bad thing to have in there at that point to make visualization a little easier--having two more digits tacked onto the base name would really make it hard to scan visually. You could, of course, just use REN to do a substitution to make it go away...
B. I'm working on it... :) I have yet another meeting this evening here in a few minutes and had to spend the day catching up on farm work after rain and being gone yesterday so "all's been quiet on this front" for most part...
I did download the toolset from FEX so at least should be able to run the functions for the file or two that do have when get that far along...
C G
C G 2018년 8월 10일
No worries on time. I am slowly working through my code and getting stuff that looks fine.
The naming convention has been a blessing. I have 5 %HT that I am working with. It makes my life easier if I accidentally mix up the variables, I can easily sort through them. Yay! Happy accident!

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

답변 (1개)

C G
C G 2018년 8월 7일
편집: C G 2018년 8월 10일
delimiterIn = ' ';
headerlinesIn = 13;
% Create an empty Table that will hold ALL imported data
z1Data = [];
% Use 'for loop' to import all the data into one place
for i = 3625:4344 %Set this to the number of files you want to import.
C = importdata(tdumpnamesOneHr(i),delimiterIn,headerlinesIn);
z1Data = [z1Data C.data(:,3:15)];
end
%Now let's loop through all of the kmmetersTraveled.
kmmetersTraveled1 = pathdist(z1Data(:,8),z1Data(:,9),'km');
DateNumber = 1900 + (decyear([z1Data(:,1),z1Data(:,2),z1Data(:,3),z1Data(:,4),z1Data(:,5),z1Data(:,6)]));
figure
subplot(2,2,1)
sz = 15;
scatter(DateNumber(2,:),kmmetersTraveled1(2,:),sz,'b.','filled');
box off;
xlabel('time')
ylabel('kilometers traveled')
hold on;
for j = 14:13:size(z1Data,2)
DateNumber = 1900 + (decyear([z1Data(:,j),z1Data(:,j+1),z1Data(:,j+2),z1Data(:,j+3),z1Data(:,j+4),z1Data(:,j+5)]));
kmmetersTraveled = pathdist(z1Data(:,j+7),z1Data(:,j+8),'km');
scatter(DateNumber(2,:),kmmetersTraveled(2,:),sz,'b.');
end
%Now calculate and plot speed in m/s.
subplot(2,2,2)
speed_1 = (((kmmetersTraveled)*1000)/3600);
DateNumber = 1900 + (decyear([z1Data(:,1),z1Data(:,2),z1Data(:,3),z1Data(:,4),z1Data(:,5),z1Data(:,6)]));
scatter(DateNumber(2,:),speed_1(2,:),sz,'b.','filled');
box off;
xlabel('time')
ylabel('speed (m/s)')
hold on;
for j = 14:13:size(z1Data,2)
DateNumber = 1900 + (decyear([z1Data(:,j),z1Data(:,j+1),z1Data(:,j+2),z1Data(:,j+3),z1Data(:,j+4),z1Data(:,j+5)]));
kmmetersTraveled = pathdist(z1Data(:,j+7),z1Data(:,j+8),'km');
speed_1 = (((kmmetersTraveled)*1000)/3600);
scatter(DateNumber(2,:),speed_1(2,:),sz,'b.');
end
%Plot Atmospheric Pressure
subplot(2,2,3)
DateNumber2 = 1900 + (decyear([z1Data(:,j),z1Data(:,j+1),z1Data(:,j+2),z1Data(:,j+3),z1Data(:,j+4),z1Data(:,j+5)]));
%scatter(DateNumber2(1,:),z1Data(1,11),sz,'r.'); hold on;
scatter(DateNumber2(2,:),z1Data(2,11),sz,'b.');
box off;
xlabel('time')
ylabel('hPa')
hold on;
for j = 14:13:size(z1Data,2)
DateNumber2 = 1900 + (decyear([z1Data(:,j),z1Data(:,j+1),z1Data(:,j+2),z1Data(:,j+3),z1Data(:,j+4),z1Data(:,j+5)]));
%scatter(DateNumber2(1,:),z1Data(1,j+10),sz,'r.'); hold on;
scatter(DateNumber2(2,:),z1Data(2,j+10),sz,'b.');
end
%Plot Temperature.
subplot(2,2,4)
DateNumber2 = 1900 + (decyear([z1Data(:,j),z1Data(:,j+1),z1Data(:,j+2),z1Data(:,j+3),z1Data(:,j+4),z1Data(:,j+5)]));
scatter(DateNumber2(2,:),z1Data(2,13),sz,'b.');
box off;
xlabel('time')
ylabel('Degrees (°C)')
hold on;
for j = 14:13:size(z1Data,2)
DateNumber2 = 1900 + (decyear([z1Data(:,j),z1Data(:,j+1),z1Data(:,j+2),z1Data(:,j+3),z1Data(:,j+4),z1Data(:,j+5)]));
scatter(DateNumber2(2,:),z1Data(2,j+12),sz,'b.');
end

카테고리

Help CenterFile Exchange에서 Low-Level File I/O에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by