Code Not working...sort of

1 visualizzazione (ultimi 30 giorni)
C G
C G il 6 Ago 2018
Modificato: C G il 10 Ago 2018
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 Commenti
dpb
dpb il 10 Ago 2018
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 il 10 Ago 2018
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!

Accedi per commentare.

Risposte (1)

C G
C G il 7 Ago 2018
Modificato: C G il 10 Ago 2018
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

Community Treasure Hunt

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

Start Hunting!

Translated by