Code won't run more then once correctly

When I run the code provided, it works, then when I try to run it again it doesn't go all the way through, spits out data and doesn't create the plots desired. I can clear all, clc and then it runs correctly but it doesn't work again. Please provide feedback when you get the chance. Thank You.
%%Shear Beam - Analysis
clear all
close all
clc
set(0,'DefaulttextFontName','Times New Roman')
set(0,'DefaultAxesFontName', 'Times New Roman')
set(0,'DefaultAxesFontSize',12)
set(0,'DefaultTextFontSize',14)
addpath(genpath('J:/Research/Testing'))
load PS_0SR_192_72_NC_V_data.txt;
%%A. Data Location
data = PS_0SR_192_72_NC_V_data;
time = data(:,1);
mark = data(:,2);
SP1 = data(:,3)*-1;
SP2 = data(:,4)*-1;
SP3 = data(:,5)*-1;
Tilt0 = data(:,6);
Tilt1 = data(:,7);
PB = data(:,8);
T2 = {'SP1 - Quarter Point','SP2 - Midsan','SP3 - Quarter Point'};
SP = [SP1 SP2 SP3];
m1 = min(find(time==0));
m4 = max(find(time==2749.121715));
m2 = (find(time==1176.021716));
m3 = (find(time==1176.221715));
tm_fixed = [m1:m2 m3:m4];
%%B. Load vs Deflection
x = repmat((0:0.25:0.75),3,1);
plot(SP1(tm_fixed),PB(tm_fixed),'color',x(1:3,1))
hold on;
plot(SP2(tm_fixed),PB(tm_fixed),'color',x(1:3,3))
hold on;
plot(SP3(tm_fixed),PB(tm_fixed),'color',x(1:3,4))
axis([0 .2 0 100000])
grid
legend('QuaterPoint','Midspan','EndPoint','Location','southeast');
title('UHPC Load vs Deflection','fontsize',14)
xlabel('Deflection, in. (mm)')
ylabel('Load, kips (kN)')
hold on;
for i =1:3
figure;
co = [x(1:3,1) x(1:3,3) x(1:3,4)];
SPx=SP(:,i);
plot(SPx(tm_fixed),PB(tm_fixed),'color',co(:,i(1,1)))
hold on;
axis([0 .2 0 100000])
grid
legend(T2(1,i),'Location','SouthEast');
title('UHPC Load vs Deflection','fontsize',14)
xlabel('Deflection, in. (mm)')
ylabel('Load, kips (kN)')
hold on;
end
hold off

 Accepted Answer

What do you learn when you step through it line by line in the debugger? I bet that would tell you what lines of code it's executing and let you know what the problem is. You didn't attach PS_0SR_192_72_NC_V_data.txt so we can't run your code to test it - you have to do that.

3 Comments

I left an answer with the file attached. Thank you for your help.
I ran it several times. All times it produced 4 figures. It never failed to run.
Hmm. Weird. Well thanks for you help.

Sign in to comment.

More Answers (2)

In the line before
for i =1:3
change the hold on to hold off

1 Comment

I tried doing that and it still will only run correctly after I clear all and close all in the command window. Thank you for the help.

Sign in to comment.

CPdaCE
CPdaCE on 4 Aug 2015
Thank you for the speedy response. Here is the file that I used to build the plots and what not. And I have not tried/heard of the debugger I will try it out. Also, changing hold off did not fix the problem. Let me know if you guys figure anything else out. Thank you again.

Categories

Find more on Programming in Help Center and File Exchange

Asked:

on 4 Aug 2015

Commented:

on 5 Aug 2015

Community Treasure Hunt

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

Start Hunting!