Clear Filters
Clear Filters

loglog plot command not working,gives linear plot

111 views (last 30 days)
function f_plot(sr)
load(sr);
% nf=0;
lstr={'PTT predictions-0.1/s','Expt. Data-0.1/s','PTT predictions-0.3/s','Expt. Data-0.3/s','PTT predictions-1/s','Expt. Data-1/s','PTT predictions-3/s','Expt. Data-3/s','PTT predictions-10/s','Expt. Data-10/s'};
colorstring = 'kbgry';
figure(1); cla;
for i=1:1:no_of_eps_dot
% nf=nf+1;
% figure(nf);
hold on; grid on;
[mm ii]=find(ext_visc{i}<1e10);
plot(allt{i}(mm),ext_visc{i}(mm),'color',colorstring(i),'linewidth',1.5);
hold on
plot(t_expt{i},visc_expt{i},'*','color',colorstring(i));
xlabel('Time (sec)');
ylabel('Extensional Viscosity (Pa-sec)');
set(gca,'xLim',[0 20]);
set(gca,'yLim',[-0.5 1*10^5]);
name=sprintf('PTT Extensional Rheology :Plot of Extensional Viscosity vs time for Extensional rate for 2.PENC.');
title(name);
legend(lstr);
end
end
%
[SL: edited to apply code formatting]

Answers (2)

Steven Lord
Steven Lord on 22 Jan 2018
When I search this page for "loglog" (before writing this comment) I only found four hits and none of them were in your code. If one of the plot calls was supposed to be a loglog call, this is the expected behavior.
The first thing you do inside your loop is turn hold on. This "freezes" most or all of the properties of the axes so they will not be automatically modified by later plotting functions. One of the families of properties that hold on freezes is the scale: linear or log. Since no axes existed when that command was run, MATLAB populates the figure with a linear scale axes and freezes its properties. If you later call loglog to try to create a plot in that axes, it isn't allowed to change the XScale and YScale properties of the axes.
This is documented in the documentation for the loglog function: "If you attempt to add a loglog, semilogx, or semilogy plot to a linear axis mode graph with hold on, the axis mode remains as it is and the new data plots as linear."
To do what you want, add multiple plots to an axes in log scale, you will need to change the scale properties of the axes. You can do that before calling hold:
figure
% X scale will be logarithmic, y scale will be linear
axes('XScale', 'log', 'YScale', 'linear')
hold on
plot(1:10, 1:10)
or after:
figure
hold on
% x scale will be linear, y scale will be logarithmic
set(gca, 'YScale', 'log')
plot(1:10, 1:10)

Jan
Jan on 22 Jan 2018
At first a simplified version of your code:
function f_plot(sr)
load(sr); % BAD idea, now it is not clear, which variable have been imported
% Prefer: data = load(sr)
lstr = {'PTT predictions-0.1/s','Expt. Data-0.1/s','PTT predictions-0.3/s', ...
'Expt. Data-0.3/s','PTT predictions-1/s','Expt. Data-1/s', ...
'PTT predictions-3/s','Expt. Data-3/s','PTT predictions-10/s', ...
'Expt. Data-10/s'};
colorstring = 'kbgry';
figure(1);
AxesH = axes('NextPlot', 'add'); % Equivalent to: hold('on')
for i = 1:no_of_eps_dot
[mm, ii] = find(ext_visc{i}<1e10);
plot(allt{i}(mm), ext_visc{i}(mm), 'color', colorstring(i), 'linewidth', 1.5);
plot(t_expt{i}, visc_expt{i}, '*', 'color', colorstring(i));
end
grid on;
xlabel('Time (sec)');
ylabel('Extensional Viscosity (Pa-sec)');
set(AxesH, 'XLim', [0 20], 'YLim',[-0.5, 1e5]);
% Without SPRINTF:
name = ['PTT Extensional Rheology :Plot of Extensional Viscosity vs ', ...
'time for Extensional rate for 2.PENC.'];
title(name);
legend(lstr);
end
Now you do not set the parameters of the axes in each iteration, but once only.
You are asking for a loglog plot, but did not specify any log scaling anywhere. The X limits are [0, 20], and 0 is not a valid limit for a log scale.
So what is your actual question? Do you want to append:
set(AxesH, 'YScale', 'log')
?
  2 Comments
Dnyaneshwar Gawande
Dnyaneshwar Gawande on 22 Jan 2018
ok sir,here i am providing you full programm & still the qustion is same i.e-loglog plot command not working,gives linear plot and i have to change axes scale from linear to log everytim
function f_PTT_uniax_ext(varargin)
% This function integrates PTT Equation under Uniaxial extensional flow kinematics. % This requires following parameters as input
% extensional rate (1/sec) = eps_dot(j=1 to 5)=[0.1 0.3 1 3 10] % beta=eps; To avoid confusion here with strain I call epsilon eps in the original equation as beta % beta is a parameter which shows up in the exponent term % zeta is a parameter from the G-S Derivative
% zeta = Parameter = ptt_zeta (i=1 to 8) it may be same or different for 8 % modes and is typically taken as 0 for LLDPE and 0.18 for LDPE % beta = Parameter = rp_beta (i=1 to 8) it may be same or different for 8 % modes and is typically taken as 0.35 for LLDPE and 0.065 for LDPE
%%%%%%%%%%%%%%%%%%%%%% PTT fitting parameters %%%%%%%%%%%%%%%%%%%%%%
% % for LLDPE 2045G: beta or eps=0.32 - 0.38; zeta=0 % % for LDPE 170A: beta or eps=0.065; zeta=0.18
% Tau_d = Reptation relaxation time (sec) = ld(i=1 to 8) = represents only % G = Reptation relaxation modulus (Pa) % tspan = [0 500] = time span for which experiment continues (sec)
% This code will yield the following things: % Txx - total and individual mode stress in stretching direction (Pa) % Tyy - total and individual mode stress in transverse direction (Pa) % Tzz - total and individual mode stress in z-direction (Pa) % Eta_plus - (Txx-Tyy)/eps_dot = transient extensional viscosity (Pa-sec)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
close all; clear all; clc;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
resin_no=1; % 2.5PENC
iexcel=1; % Set this parameter 1 if you want to write an excel file of output iplot=1; % Set this parameter 1 if you want to plot the results
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if resin_no==1
resin='2.5PENC';
resin1={'2.5PENC'};
G=[441055 170367 56521.9 21301.5 8411.24 3113.92 1111.98 371.166]; % Relaxation Modulus for 2.5PENC in Pa at test temp. of 150C;
ld=[3.39E-04 2.60E-03 0.0130633 0.0468255 0.161813 0.577485 2.12091 7.71414]; % Reptation reaxation time for 2.5PENC in sec. at test temp. of 150C;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Input Parameters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ptt_beta=[.01]; % PTT beta or eps or epsilon Parameter ptt_zeta=[0.0]; % PTT zeta or G-S Parameter tspan=[0 500]; % Time span eps_dot=[0.1 0.3 1 3 10]; % Extensional strain rates
% Total stress at the start of stretching expt. i.e. @ t=0; Initial guess values for stresses
Txx_total=0; Tyy_total=0;
%%%%%%%%%%%%%%% Consistency Check no. of modes %%%%%%%%%%%%%%%%%%%%%
no_of_mode=length(ld); no_of_eps_dot=length(eps_dot);
%%% Distribution of total stresses over individual modes %%%%%%%%%%%%
dim=2*no_of_mode; % Matrix Dimensions
for k=1:2:dim
i=(k+1)/2;
yint(k,1)=Txx_total*G(i)/sum(G);
yint(k+1,1)=Tyy_total*G(i)/sum(G);
end
for i=1:1:no_of_eps_dot [tempx_expt,tempy_expt]=(f_read(eps_dot(i))); t_expt{i}=tempx_expt; visc_expt{i}=tempy_expt; end
%%%%%%%%%%%%%%%%%%%%%%%%% Integration step %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:1:no_of_eps_dot eps_dot(i) [t,y]=ode15s(@(t,y) fequa(t,y,eps_dot(i),ld,ptt_beta,ptt_zeta,G),tspan,yint); allt{i}=t; ally{i}=y;
nt=length(allt{i});
sumxx{i}=zeros(nt,1);
sumyy{i}=zeros(nt,1);
ext_visc{i}=zeros(nt,1);
for k=1:2:dim
sumxx{i}(:,1)=sumxx{i}(:,1)+ally{i}(:,k);
sumyy{i}(:,1)=sumyy{i}(:,1)+ally{i}(:,k+1);
end
ext_visc{i}(:,1)=((sumxx{i}(:,1))-(sumyy{i}(:,1)))/eps_dot(1,i); % calculating eta e plus
sr=sprintf('PTT_%s_Uniax_Ext.mat',resin);
save(sr)
end
if iexcel==1 f_excel(sr); else disp('Not writing excel output file, set iexcel=1, if you wish to write excel output file.') end
if iplot==1 f_plot(sr); else disp('Not plotting, set iplot=1, if you wish to plot result.') end
end
%%%%%%%%%%%%%%%%%% Function for Inverting Matrix %%%%%%%%%%%%%%%%%%%%%%%%%
function yprime = fequa(t,y,eps_dot,ld,ptt_beta,ptt_zeta,G)
no_of_mode=length(ld);
dim=2*no_of_mode; % Dimensions of matrix
amat=zeros(dim,dim);
rhs=zeros(dim,1);
for k=1:2:dim
j=(k+1)/2; % Mode number
amat(k,k)=1;
amat(k+1,k+1)=1;
term_1(j)=exp((ptt_beta/G(j))*(y(k)+2*y(k+1))); % exponential term
rhs(k,1)=((2*eps_dot)*(G(j)+y(k)-(ptt_zeta*y(k))))-(y(k)*term_1(j)/ld(j));
rhs(k+1,1)=-eps_dot*(G(j)+(y(k+1)-((ptt_zeta)*y(k+1))))-(y(k+1)*term_1(j)/ld(j));
end
yprime=amat\rhs;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Writing Excel File %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function f_excel(sr);
load (sr);
str1={'Txx'}; str2={'Tyy'};
rname=cell(1,dim);
for k=1:2:dim i=(k+1)/2;
m=num2str(i);
rname(1,k)=strcat(str1,m);
rname(1,k+1)=strcat(str2,m);
end rname(1,dim+1)={'Total Txx (Pa)'}; rname(1,dim+2)={'Total Tyy (Pa)'}; rname(1,dim+3)={'Extensional Viscosity( Pa-sec)'};
fi_name=sprintf('PTT_Uniax_Ext_2.5PENC',resin); fi_name=strcat(fi_name,'.xlsx');
xlswrite(fi_name,{'Resin='},1,'A2'); xlswrite(fi_name,resin1,1,'B2');
xlswrite(fi_name,{'Rel. Modulie(Pa)'},1,'B4'); xlswrite(fi_name,{'Reptation Rel. Time(sec)'},1,'C4'); xlswrite(fi_name,{'PTT_Beta'},1,'D4'); xlswrite(fi_name,{'PTT_Zeta'},1,'E4');
xlswrite(fi_name,G',1,'B6:B13'); xlswrite(fi_name,ld',1,'C6:C13'); xlswrite(fi_name,ptt_beta',1,'D6:D13'); xlswrite(fi_name,ptt_zeta',1,'E6:E13');
for i=1:1:no_of_eps_dot sheet_name=sprintf('Ext Rate=%g',eps_dot(i)); warning off MATLAB:xlswrite:AddSheet xlswrite(fi_name,{'t(sec)'},sheet_name,'A3'); xlswrite(fi_name,rname,sheet_name,'B3'); xlswrite(fi_name,[allt{i},ally{i},sumxx{i},sumyy{i},ext_visc{i}],sheet_name,'A5'); end
end
%%%%%%%%%%%%%%%%%%%%%%%%% Matlab Plotting %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function f_plot(sr) load(sr); % BAD idea, now it is not clear, which variable have been imported % Prefer: data = load(sr) lstr = {'PTT predictions-0.1/s','Expt. Data-0.1/s','PTT predictions-0.3/s', ... 'Expt. Data-0.3/s','PTT predictions-1/s','Expt. Data-1/s', ... 'PTT predictions-3/s','Expt. Data-3/s','PTT predictions-10/s', ... 'Expt. Data-10/s'}; colorstring = 'kbgry'; figure(1); AxesH = axes('NextPlot', 'add'); % Equivalent to: hold('on') for i = 1:no_of_eps_dot [mm, ii] = find(ext_visc{i}<1e10); loglog(allt{i}(mm), ext_visc{i}(mm), 'color', colorstring(i), 'linewidth', 1.5); loglog(t_expt{i}, visc_expt{i}, '*', 'color', colorstring(i)); end grid on; xlabel('Time (sec)'); ylabel('Extensional Viscosity (Pa-sec)'); set(AxesH, 'XLim', [0.0005 1000], 'YLim',[1000, 1000000]); % Without SPRINTF: name = ['PTT Extensional Rheology :Plot of Extensional Viscosity vs ', ... 'time for Extensional rate for 2.5PENC.']; title(name); legend(lstr); end function [x_expt,y_expt]= f_read(eps_dot)
sr='EVF EXPERIMENTAL DATA.xlsx';
if eps_dot==0.1
x_expt=xlsread(sr,'EVF-2.5NC','C2:C1900');
y_expt=xlsread(sr,'EVF-2.5NC','D2:D1900');
elseif eps_dot==0.3
x_expt=xlsread(sr,'EVF-2.5NC','E2:E1100');
y_expt=xlsread(sr,'EVF-2.5NC','F2:F1100');
elseif eps_dot==1
x_expt=xlsread(sr,'EVF-2.5NC','G2:G351');
y_expt=xlsread(sr,'EVF-2.5NC','H2:H351');
elseif eps_dot==3
x_expt=xlsread(sr,'EVF-2.5NC','I2:I122');
y_expt=xlsread(sr,'EVF-2.5NC','J2:J122');
elseif eps_dot==10
x_expt=xlsread(sr,'EVF-2.5NC','K2:K34');
y_expt=xlsread(sr,'EVF-2.5NC','L2:L34');
end
end
%
Dnyaneshwar Gawande
Dnyaneshwar Gawande on 22 Jan 2018
HI Sir,many many thanks. set(AxesH, 'xScale', 'log')&set(AxesH, 'YScale', 'log') has done the job

Sign in to comment.

Categories

Find more on Preprocessing Data in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!