I am trying to do a 3d graph of a excel file that is 343 by 81 cells, The first column needs to be the X and the first row needs to be the Y and the remaining matrix needs to be the Z. I have the data successfully imported from excel and I create a matrix of the first column called energy (343,1)(x-axis), while creating a row matrix (1, 81) called Time Delay(y-axis) and a (343,81) matrix where the first column and row is zero called Absorbance Change(Z-axis). I've got the proper 3d graph that I need but I need the axes shown in the graph to be that of the Energy and Time Delay instead of the indices of the Absorbance Change matrix. I am putting the relevant portion of the code below as well as a picture of the graph:
EnergyString = dataArray{:, 1};
EnergyString(1,1) = {'0'};
Energy = str2double(EnergyString);
%Energy = [ Energy, zeros(343, 80) ];
TimeDelay = [ z1(1,1), z2(1,1), z3(1,1), z4(1,1), z5(1,1), z6(1,1), z7(1,1), z8(1,1), z9(1,1), z10(1,1), z11(1,1), z12(1,1), z13(1,1), z14(1,1), z15(1,1), z16(1,1), z17(1,1), z18(1,1), z19(1,1), z20(1,1), z21(1,1), z22(1,1), z23(1,1), z24(1,1), z25(1,1), z26(1,1), z27(1,1), z28(1,1), z29(1,1), z30(1,1), z31(1,1), z32(1,1), z33(1,1), z34(1,1), z35(1,1), z36(1,1), z37(1,1), z38(1,1), z39(1,1), z40(1,1), z41(1,1), z42(1,1), z42(1,1), z43(1,1), z44(1,1), z45(1,1), z46(1,1), z47(1,1), z48(1,1), z49(1,1), z50(1,1), z51(1,1), z52(1,1), z53(1,1), z54(1,1), z55(1,1), z56(1,1), z57(1,1), z58(1,1), z59(1,1), z60(1,1), z61(1,1), z62(1,1), z63(1,1), z64(1,1), z65(1,1), z66(1,1), z67(1,1), z68(1,1), z69(1,1), z70(1,1), z71(1,1), z72(1,1), z73(1,1), z74(1,1), z75(1,1), z76(1,1), z77(1,1), z78(1,1), z79(1,1), z80(1,1) ];
%TimeDelay = [ TimeDelay; zeros(342, 81)];
startRow formatSpec filename fileID delimiter ans EnergyString Alpha Beta Gamma Delta Epsilon Zeta Eta Theta Iota Kappa Lambda Mu Nu Xi Omicron Pi Rho Sigma Tau Upsilon Phi Chi Psi Omega AlphaAlpha AlphaBeta AlphaGamma AlphaDelta AlphaEpsilon AlphaZeta AlphaEta AlphaTheta AlphaIota AlphaKappa AlphaLambda AlphaMu AlphaNu AlphaXi AlphaOmicron AlphaPi AlphaRho AlphaSigma AlphaTau AlphaUpsilon AlphaPhi AlphaChi AlphaPsi AlphaOmega BetaAlpha BetaBeta BetaGamma BetaDelta BetaEpsilon BetaZeta BetaEta BetaTheta BetaIota BetaKappa BetaLambda BetaMu BetaNu BetaXi BetaOmicron BetaPi BetaRho BetaSigma BetaTau BetaUpsilon BetaPhi BetaChi BetaPsi BetaOmega GammaAlpha GammaBeta GammaGamma GammaDelta GammaEpsilon GammaZeta GammaEta GammaTheta; %Delete Excess Varaible
AbsorbanceChange = [ zeros(343, 1), z1, z2, z3, z4, z5, z6, z7, z8, z9, z10, z11, z12, z13, z14, z15, z16, z17, z18, z19, z20, z21, z22, z23, z24, z25, z26, z27, z28, z29, z30, z31, z32, z33, z34, z35, z36, z37, z38, z39, z40, z41, z42, z43, z44, z45, z46, z47, z48, z49, z50, z51, z52, z53, z54, z55, z56, z57, z58, z59, z60, z61, z62, z63, z64, z65, z66, z67, z68, z69, z70, z71, z72, z73, z74, z75, z76, z77, z78, z79, z80];
AbsorbanceChange(1,:) = 0;
clear z1 z2 z3 z4 z5 z6 z7 z8 z9 z10 z11 z12 z13 z14 z15 z16 z17 z18 z19 z20 z21 z22 z23 z24 z25 z26 z27 z28 z29 z30 z31 z32 z33 z34 z35 z36 z37 z38 z39 z40 z41 z42 z43 z44 z45 z46 z47 z48 z49 z50 z51 z52 z53 z54 z55 z56 z57 z58 z59 z60 z61 z62 z63 z64 z65 z66 z67 z68 z69 z70 z71 z72 z73 z74 z75 z76 z77 z78 z79 z80;
mesh(AbsorbanceChange)
colorbar
title('WS2-Perovskite-image')
xlabel('Energy') % x-axis label
ylabel('Time-delay') % y-axis label
zlabel('Absorbance Change')
When I type help mesh in MATLAB I see, among other thins, this:
mesh(x,y,Z) and mesh(x,y,Z,C), with two vector arguments replacing
the first two matrix arguments, must have length(x) = n and
length(y) = m where [m,n] = size(Z). In this case, the vertices
of the mesh lines are the triples (x(j), y(i), Z(i,j)).
Note that x corresponds to the columns of Z and y corresponds to
the rows.
Thus, you can do
mesh(Energy, TimeDelay, AbsorbanceChange);
I don't know how you read the data from file, but there is a better way than specifying each cell individually in your code.
How Can I use ezplot to plot something like this:
syms Vg L a b z c
c=sym('a*Vg+z');
A=sym('a*Vg+b+c*L');
A=subs(A,[a b z],[1 2 3]);
ezplot(A)
where I want to plot Vg versus L.
The point is that A contains another sym which is c.
The above code yields an error.
The error when running your example is quite telling;
"The number of variables must not exceed two when plotting an equation".
In your case, you're attempting to implicitly plot a function which contains three variables; the output of your symbolic equation is
...
A =
Vg + L*c + 2
Now, from the reference documentation of ezplot:
Passing Additional Arguments
If your function has additional parameters, for example k in myfun:
function z = myfun(x,y,k)
z = x.^k - y.^k - 1;
then you can use an anonymous function to specify that parameter:
ezplot(#(x,y)myfun(x,y,2))
Hence, one alternative is to can create a function for this 3-variable expression:
% myfun.m
function z = myfun(Vg,L,c)
z = Vg + L.*c + 2;
end
And thereafter use ezplot by calling this function with an anonymous function for the first two parameters (#(Vg,L)), and a fixed value of the third (c).
Example usage, repeated ezplot:s for varying (fixed) values of c:
% plot 'Vg + L*c + 2 = 0' for values of c in [0,5]
hold on, box on
for c = 0:0.05:5
ezplot(#(Vg,L)myfun(Vg,L,c))
end
As another alternative, you could simply use subs(...) for e.g. the Vg symbolic to plot the implicit function for the remaining two for varying (fixed) values of Vg:
syms Vg L a b z c
c=sym('a*Vg+z');
A=sym('a*Vg+b+c*L');
A=subs(A,[a b z],[1 2 3]);
hold on, box on
for VgVal = -6:6
ezplot(subs(A, Vg, VgVal))
end
title([char(A), ', with Vg \in [-6, 6]'])
I need to generate two chaotic sequences based on chen's hyperchaotic system.It has to be generated from the following four formulas
X=ay-x;
Y=-xz+dx+cy-q;
Y=xy-bz;
Q=x+k;
where a,b,c,d,x,y,z,q are all initialised as follows.
I need only X and Y
where
X=[x1,x2,...x4n]
Y=[y1,y2,...y4n]
a=36 ;
b=3 ;
c=28 ;
d=16 ;
k=0.2 ;
x=0.3 ;
y=-0.4 ;
z=1.2 ;
q=1 ;
n=256 ;
I tried the following code but i'm not able to get it properly.
clc
clear all
close all
w=imread('C:\Users\Desktop\a.png');
[m n]=size(w)
a=36;
b=3;
c=28;
d=16;
k=0.2;
x(1)=0.3;
y(1)=-0.4;
z(1)=1.2;
q(1)=1;
for i=1:1:4(n)
x(i+1)=(a*(y(i)-x(i)));
y(i+1)=-(x(i)*z(i))+(d*x(i))+(c*y(i))-q(i);
z(i+1)=(x(i)*y(i))-(b*z(i));
q(i+1)=x(i)+k;
end
disp(x);
disp(y);
pls help. thanks in advance.
Your code isn't even close to doing what you want it to. Fortunately, I'm vaguely interested in the problem and I have a bunch of spare time, so I thought I'd try and implement it step by step to show you what to do. I've left a few gaps for you to fill in.
It sounds like you want to integrate the hyperchaotic chen system, which has various definitions online, but you seem to be focusing on
So let's write a matlab function that defines that system
function vdot = chen(t, v, a, b, c, d, k)
% Here you unpack the input vector v -
x = v(1); y = v(2); z = v(3); q = v(4);
% Here you need to implement your equations as xdot, ydot etc.
% xdot = ...
% ydot = ...
% I'll leave that for you to do yourself.
% Then you pack them up into an output vector -
vdot = [xdot; ydot; zdot; qdot];
end
Save that in a file called chen.m. Now you need to define the values of the parameters a, b, c, d and k, as well as your initial condition.
% You need to define the values of a, b, c, d, k here.
% a = ...
% b = ...
% You also need to define the vector v0, which is a 4x1 vector of your
% initial conditions
% v0 = ...
%
This next line creates a function that can be used by Matlab's integration routines. The first parameter t is the current time (which you don't actually use) and the second parameter is a 4x1 vector containing x, y, z, q.
>> fun = #(t,v) chen(t,v,a,b,c,d,k)
Now you can use ode45 (which does numerical integration using a 4th order runge-kutta scheme) to integrate it and plot some paths. The first argument to ode45 is the function you want to be integrated, the second argument is the timespan to be integrated over (I chose to integrate from 0 to 100, maybe you want to do something different) and the third argument is your initial condition (which hopefully you already defined).
>> [t, v] = ode45(fun, [0 100], v0);
The outputs are t, a vector of times, and v, which will be a matrix whose columns are the different components (x, y, z, q) and whose rows are the values of the components at each point in time. So you can pull out a column for each of the x and y components, and plot them
>> x = v(:,1);
>> y = v(:,2);
>> plot(x,y)
Which gives a reasonably chaotic looking plot:
#Abirami Anbalagan and Sir #Chris Taylor, I have also studied hyperchaotic system up to some extent. According to me, for system to be chaotic, values should be like
a= 35; b= 3; c= 12; d= 7;
v(n) = [-422 -274 0 -2.4]transpose
where v(n) is a 4*1 Matrix.
In MATLAB, I am trying to create a matrix of the outputs of the built-in function [r, p] = corr(X1,Y1); after using this function on multiple X's and Y's. Then, I would like to consolidate all of the r and p into their respective matrices, R and P. For example, I can do this easily if I only call one output from corr:
R = [corr(X1,Y1), corr(X2,Y2); (...)
corr(X3,Y3), corr(X4,Y4)];
as corr returns the r value by default. Is there a way to achieve this for p as well? Below is the long way that I do it, I'm just wondering whether there is a shorter and easier method like above.
First find each r and p:
[r1, p1] = corr(X1,Y1);
[r2, p2] = corr(X2,Y2);
[r3, p3] = corr(X3,Y3);
....
Then combine them into the matrix:
R = [r1 r2; (...)
r3 r4; (...)
...];
P = [p1 p2; (...)
p3 p4; (...)
...];
Thanks.
You can try something along the lines of
for i=1:n,
[R(:,end+1), P(:,end+1)] = corr(X(:,i), Y(:,i));
end
Just make sure that R(:,1) and P(:,1) are sized correctly.
Assigning R(:,end+1) and P(:,end+1) will grow R and P automatically, without your having to combine them from temporary variables by hand.
I need to run a simple Monte Carlo varying coefficients on a system of equations. I need to record the solved coefficient of one of the variables each time.
The following gets me results from a single run:
syms alpha gamma Ps Pc beta lambda Pp Sp Ss Dp Ds;
eq1 = -Ss + alpha + 0.17*Ps - 1*Pc;
eq2 = -Sp + beta + 0.2*Pp;
eq3 = -Ds + gamma - 0.2*Ps + 1*Pp;
eq4 = -Dp + lambda - 0.17*Pp + 1*Ps;
eq5 = Ss - Ds;
eq6 = Sp - Dp;
ans1 = solve(eq1,eq2,eq3,eq4,eq5,eq6,'Ps','Pp','Ss','Ds','Sp','Dp');
disp('Ps')
vpa(ans1.Ps,3)
disp('Pp')
vpa(ans1.Pp,3)
disp('Ss')
vpa(ans1.Ss,3)
disp('Ds')
vpa(ans1.Ds,3)
disp('Sp')
vpa(ans1.Sp,3)
disp('Dp')
vpa(ans1.Dp,3)
I will be varying several of the variables (on Ps, Pp, and Pc), and recording the coefficient on Pc in each of the reduced form equations (i.e. the coefficient on Pc that shows up after vpa(ans1.xx)--so in the case above, it would be a 1x6 vector [-0.429,-1.16,-1.07,-1.07,-0.232,-0.429,-1.16]).
I'm very new to MATLAB, but I'm sure I can figure out how to implement the loop code to do the model iterations. What I can't figure out is how to record the vector of coefficients after each iteration. Is there some "accessor" that will give me just the one coefficient for each equation each time?
Something like vpa(ans1.ps.coef(pc)) (which is a total shot in the dark, and it's wrong, but hopefully you get the idea).
There's probably a better way to do this, but this is all I could come up to at this moment.
Step 1:
In order to obtain the coefficient of Pc as a double from ans1.Ps, you can use the subs function, as follows:
subs(ans1.Ps,{alpha,Pc,beta,gamma,lambda},{0,1,0,0,0});
Step 2a:
To get a vector of all coefficients per ans1 expression (say ans1.Ps) you can use something like this:
N=numel(symvar(ans1.Ps)); % obtain number of coefs
cp=num2cell(eye(N)); % create a cell array using unit matrix, so each iteration a different coef will be selected
for n=1:N;
coefs(n)=subs(ans1.Ps,{alpha,Pc,beta,gamma,lambda},cp(n,:));
end
Step 2b:
Alternatively, you want to get just Pc, but from all the ans1 expressions. If so then you can do the following:
SNames = fieldnames(ans1); % get names of ans1 expressions
for n = 1:numel(SNames)
expr = ans1.(SNames{n}); % get the expression itself
pc(n)=subs(expr,{alpha,Pc,beta,gamma,lambda},{0,1,0,0,0}); % obtain just pc
end
You can now combine the two if you want all info about the coefficients.
Edit:
To store the retrieved Pc per iteration you can do the following:
alpha=[3 1 4 6 7] % just a vector of values
beta = [6 7 8 5 2]
SNames = fieldnames(ans1); % get names of ans1 expressions
for n = 1:numel(SNames)
expr = ans1.(SNames{n}); % get the expression itself
for n1=1:numel(alpha)
for n2=1:numel(beta)
pc(n,n1,n2)=subs(expr,{alpha,Pc,beta,gamma,lambda},{alpha(n1),1,beta(n2),0,0})
end
end
end