https://se.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions2021-05-08T07:53:44Ztag:se.mathworks.com,2005:Question/1243532014-04-03T15:16:56Z2021-05-08T07:53:44ZDoes fitrm & ranova support within subject models without between subject factorsI am trying to use fitrm and ranova (Matlab2014a) to run a repeated measures anova on a 2x2 within subjects design. I currently have 4 variables representing the responses for all subjects in each cell of the 2x2 design.
I do not wish to include a between subject factor but rmfit seems to require at least one.
The code I am using is as follows.
alpha_power = randn(24,4); % This is my data but lets generate it for now
t = table(alpha_power(:,1),alpha_power(:,2), alpha_power(:,3), alpha_power(:,4),'VariableNames',{'Y1','Y2','Y3','Y4'}); % Create a table storing the respones
within = table({'A';'A';'V';'V'},{'T';'S';'T';'S'},'VariableNames',{'Attention','TMS'}); % Create a table reflecting the within subject factors 'Attention' and 'TMS' and their levels.
rm = fitrm(t,'Y1-Y4','WithinDesign',within); % Here the code breaks.
fitrm seems to require terms in the model specification which reflect the predictor variables (e.g. 'Y1-Y4~Gender'), but these are automatically specified as between subject factors, I do not have between subject factors.
Is it possible to specify terms as within subject factors? Jimhttps://se.mathworks.com/matlabcentral/profile/authors/3515805tag:se.mathworks.com,2005:Question/8248702021-05-08T07:52:33Z2021-05-08T07:52:33ZHow do I allow the user to save all the images of the floorplans they've created?So far the code only allows me to save the last floor plan created, rather than all of them.
e.g. if the user inputs 2 floors, only the image of the second floor shows, if the user inputs 3 floors, only the image of the floor plan of floor 3 shows o the pdf etc.
code i use to collect the floor data:
for b=1:spaces % %
rectangle('Position',[X(floorPlan,b),Y(floorPlan,b),width(floorPlan,b),depth(floorPlan,b)],'FaceColor',[0 .5 .5]);
X_text = X + width/3;
Y_text = Y + height/2;
text(X_text,Y_text,num2str(b))
saveas(gcf, "floorPlan.png" ); %
end
code is use to print image of floor data on to a pdf report:
import mlreportgen.report.*
import mlreportgen.dom.*
R = Report('Building Spatial Model report','pdf');
open(R)
tp = TitlePage;
tp.Title = 'Building Spatial Model Report';
tp.Subtitle = 'Building Spatial Structure';
tp.Author = 'my name';
add(R,tp);
plot1 = Image ( "floorPlan.png" );
plot1.Width = "7in" ;
plot1.Height = "5in" ;
add (R, plot1);
plot2 = Image ( "floorplan.png" );
plot2.Width = "7in" ;
plot2.Height = "5in" ;
add (R, plot2);
close(R)AKhttps://se.mathworks.com/matlabcentral/profile/authors/20822905tag:se.mathworks.com,2005:Question/8248602021-05-08T07:39:10Z2021-05-08T07:50:08Zwhile implementing the above code, getting error at line 8 & 10 = error is the value assigned to variable might be unsed?while implementing the above code, getting error at line 8 & 10 = error is the value assigned to variable might be unsed. plz give a solution to this problemHemen Gogoihttps://se.mathworks.com/matlabcentral/profile/authors/17803796tag:se.mathworks.com,2005:Question/8248652021-05-08T07:43:26Z2021-05-08T07:43:26ZHow MATLAB predict function compute the Negated average binary losses?Hi,
I have an multiclass SVM (onevsall) classifier trained using the classification Learner App.
It was mentioned here :
https://www.mathworks.com/help/stats/classificationecoc.predict.html#bufel6_-NegLoss
that one of the output of the predict function is an array containing the Negated average binary losses: I want to know how these Negloss values has been computed, I tried to use the equation provided in the binary loss :
https://www.mathworks.com/help/stats/classificationecoc.predict.html#bufel6__sep_sharedBinaryLoss
but I didn't get the Negloss values. How can I compute these values ?
Thank you
Akram Awadhttps://se.mathworks.com/matlabcentral/profile/authors/22462845tag:se.mathworks.com,2005:Question/8228102021-05-06T07:55:40Z2021-05-08T07:36:43Zrotating spheres using euler anglesI have two spheres separated by a distance of 2.01 units in my animation and euler angles associated with them, I want to rotate the spheres around y axis continuously how can i do that?Rishabh Katiyarhttps://se.mathworks.com/matlabcentral/profile/authors/15995916tag:se.mathworks.com,2005:Question/8218352021-05-05T03:57:06Z2021-05-08T07:19:41ZWhy do these two codes give different covariance matrices?1st code:
S =[ 0.6661 - 0.7458i 0.4210 - 0.9071i 1.0000 + 0.0000i;-0.9127 + 0.4086i -0.8429 + 0.5381i 1.0000 + 0.0000i;1.0000 + 0.0000i 1.0000 + 0.0000i 1.0000 + 0.0000i;-0.9127 - 0.4086i -0.8429 - 0.5381i 1.0000 - 0.0000i;0.6661 + 0.7458i 0.4210 + 0.9071i 1.0000 - 0.0000i];
Rmm=cov(S);
2nd code:
S =[ 0.6661 - 0.7458i 0.4210 - 0.9071i 1.0000 + 0.0000i;-0.9127 + 0.4086i -0.8429 + 0.5381i 1.0000 + 0.0000i;1.0000 + 0.0000i 1.0000 + 0.0000i 1.0000 + 0.0000i;-0.9127 - 0.4086i -0.8429 - 0.5381i 1.0000 - 0.0000i;0.6661 + 0.7458i 0.4210 + 0.9071i 1.0000 - 0.0000i];
Rmm= S*S'/length(S(1,:));
Sadiq Akbarhttps://se.mathworks.com/matlabcentral/profile/authors/966774tag:se.mathworks.com,2005:Question/8248552021-05-08T07:08:06Z2021-05-08T07:08:06ZReading particular column in one excel file and write it in new excel fileI trying to read perticular column in .xlsx file and write it in the new .xlsx file.
Kaviarasu Natarajhttps://se.mathworks.com/matlabcentral/profile/authors/18164452tag:se.mathworks.com,2005:Question/8248502021-05-08T07:05:03Z2021-05-08T07:05:03Zspeeding up trainbr using more cpu cores or a gputrainbr is slow on my computer often taking an hour. I'm looking at ways to speed it up. I'm trying to figure out if the Parallel Toolbox would help. It seems to say it would allow me to use multiple cpu cores, but when I'm running trainbr training it already looks like it is using multiple cores. Anybody know about this?
I have a GPU available but I recall reading trainbr can't use a GPU, anybody know about this?
Thank you!Brenthttps://se.mathworks.com/matlabcentral/profile/authors/5323111tag:se.mathworks.com,2005:Question/8230802021-05-06T11:11:20Z2021-05-08T07:04:07ZNeed help with Turbo product codeI am trying to encode a grsy image using turbo product code but it's not working. The code I tried is below:
clc
clear
N = [127;255];
K = [120;239];
img = imread('pout.tif');
img = de2bi(img);
resized = imresize(img,[prod(K) 1]);
enc = tpcenc(resized,N,K);
enc = double(enc);
dec = tpcdec(enc,N,K);
op_img = reshape(dec,[],8);
op_img = op_img.';
op_img = reshape(2.^(0:7)*op_img,[],15);
op_img = imresize(op_img,[290 240]);
op_img = uint8(op_img);
figure();imshow(op_img)
Can you please guide me with this?Neeraj Chimwalhttps://se.mathworks.com/matlabcentral/profile/authors/12637151tag:se.mathworks.com,2005:Question/8248452021-05-08T07:00:51Z2021-05-08T07:00:51Zreinforcement learning algorithm that is deployed online on a time varying systemHello,
I asked a similar question https://www.mathworks.com/matlabcentral/answers/822700-reinforcement-learning-lqr-example-question?s_tid=srchtitle but I want to focus on a very specific part.
I am trying to program a reinforcement learning algorithm that has to learn and control a system at the same time. I have one year hourly load data that impact the system, and I want to design an agent that needs to learn and control for that specific year given that data.
My problem is it seems to me the training phase is isolated from the simulation phase, so it's not clear to me how can I make the system advance through time during the training phase, record the state variables, and continue to the deployement phase. So my system is characterized by 8760 matrices each for every year of the hour. I want to make sure that:
1) when I train my agent for each training step that passes it advances to a new hour, basically I want to make sure my system isn't getting to try two different things in the same hour. To achieve that, do I need to make the episode length 1 ?
2) I need to have a history profile of all the actions my agent took during the training time, and the state values. In the training stats I can only see the reward per episode. I can't see the actions my agent took, nor the corrosponding state values.
I think as long as I have these two things, I should be able to deploy my system to actively learn for x many hours then control for 8760-x many hours. From the way I see in the toolbox, there doesn't seem to be a clear way to do that. Can someone clarify for me?
What I think I need to do is make my states global variables, so I can try to train for one hour only, then advance the system to next time iteration, and also store the action variable to an indexed global variable?hamad alduaijhttps://se.mathworks.com/matlabcentral/profile/authors/7832547tag:se.mathworks.com,2005:Question/8248402021-05-08T06:57:11Z2021-05-08T06:57:11ZPlot Data in realtime during a background acquisition (DAQ) with a rate of 0.1 Hz.Hi at all, I've an issue regarding this following example: https://www.mathworks.com/help/daq/acquire-continuous-and-background-data-using-ni-devices.html
In this example the sampling frequency (dq.Rate) is assigned to 2000 Hz and consequently the parameter dq.ScansAvailableFcnCount = 2000.
I've assigned the dq.Rate to 0.1 Hz (because the phenomena that i want to study are quasi-static) but now there are two issues:
1) dq.ScansAvailableFcnCount can be only an integer number (and not equal to 0.1);
2) when the plots appear on the screen i can't see the line that represent the acquired data (I can see the line if the dq.Rate is assigned, for example, to 100 Hz).
I'm using a National Instrument DAQ 6008, can you help me to solve these issues??
Thank you all!!!Ciro Tordelahttps://se.mathworks.com/matlabcentral/profile/authors/14802491tag:se.mathworks.com,2005:Question/8248352021-05-08T06:54:41Z2021-05-08T06:54:41ZHaving an Error in ncread try to open a netcdf using matlab, when I used ncread it says "Error in ncread". I don't know what's the problem because when I asked my friend to open the same file with the same script as mine on his computer it works fine without error. I try to uninstall my matlab and reinstall with several different version but it doesn't solve the problem. Any solution to fix my problem? currently I'm using matlab 2020b version. Here is script code to open my netcdf file:
ncdisp('T_Maret2016.nc');
lon=ncread('T_Maret2016.nc','Longitude');
lat=ncread('T_Maret2016.nc','Latitude');
z=ncread('T_Maret2016.nc','Depth');
time=ncread('T_Maret2016.nc','MT');
and I attached an example of variable in my netcdf file.
audi rachmanhttps://se.mathworks.com/matlabcentral/profile/authors/22473729tag:se.mathworks.com,2005:Question/4046642018-06-08T07:20:25Z2021-05-08T06:51:40ZSimulink Model of Regenerative BrakingHi is it possible to create a simulink model of regenerative braking using MATLAB? Has anyone done it before? Can you share some of your simulation? Daniel Gonzaleshttps://se.mathworks.com/matlabcentral/profile/authors/12805879tag:se.mathworks.com,2005:Question/426902012-07-03T23:42:15Z2021-05-08T06:47:55ZWarning: Name is nonexistent or not a directoryEvery time I start up MATLAB, I receive this message:
Warning: Name is nonexistent or not a directory:
C:\POSTDOC\vlfeat\toolbox\mexw32.
Warning: Name is nonexistent or not a directory:
C:\POSTDOC\vlfeat\toolbox\special.
Warning: Name is nonexistent or not a directory:
C:\POSTDOC\vlfeat\toolbox\sift.
Warning: Name is nonexistent or not a directory:
C:\POSTDOC\vlfeat\toolbox\plotop.
Warning: Name is nonexistent or not a directory:
C:\POSTDOC\vlfeat\toolbox\mser.
Warning: Name is nonexistent or not a directory:
C:\POSTDOC\vlfeat\toolbox\misc.
Warning: Name is nonexistent or not a directory:
C:\POSTDOC\vlfeat\toolbox\kmeans.
Warning: Name is nonexistent or not a directory:
C:\POSTDOC\vlfeat\toolbox\imop.
Warning: Name is nonexistent or not a directory:
C:\POSTDOC\vlfeat\toolbox\geometry.
Warning: Name is nonexistent or not a directory:
C:\POSTDOC\vlfeat\toolbox\aib.
Warning: Name is nonexistent or not a directory:
C:\POSTDOC\vlfeat\toolbox.
Warning: Name is nonexistent or not a directory: xml_toolbox.
Warning: Name is nonexistent or not a directory:
C:\POSTDOC\Hand_Mathias\videoIO.
How do I fix this?Jonathanhttps://se.mathworks.com/matlabcentral/profile/authors/3331998tag:se.mathworks.com,2005:Question/2785502016-04-12T07:55:42Z2021-05-08T06:45:48ZOptimization Problem for 4 variable functionGreetings,
I have a mathematical problem of a curve who's curvature equation is p(s) = a*s1 + b*s2 I need to find the optimized values of a, b, s1 and s2 while I know the starting and end point of curve. Does anyone know how can I do that using optimization. Thank you. Muhammad Umar Farooqhttps://se.mathworks.com/matlabcentral/profile/authors/7923406tag:se.mathworks.com,2005:Question/8247302021-05-08T02:32:36Z2021-05-08T06:45:16ZMaximizing X & YI want to maximize the value of X & Y in the below equation. The sum of X & Y cannot exceed 260.
55 * X + 100 * YSuraj Patilhttps://se.mathworks.com/matlabcentral/profile/authors/22473839tag:se.mathworks.com,2005:Question/8238052021-05-07T03:47:30Z2021-05-08T06:43:11ZWhy is the radiation pattern does not show the required steering angle?N = 16;%number of elements
wl = 1;%wavelength
k = 2.*pi./wl;
d = wl./2;%distance
f = zeros(1,180);%empty array for field
AF = zeros(1,100);%empty array for complec weights
thi = -45;%The scan angle
angle_radi = thi.*pi./180;%angle to radian
phi= (2.*pi.*d .*sin(angle_radi))./wl;%equation for phase shift
for a = 1:N %for loop to repeat until the Nth phase shift
AF(a)= (a-1).*phi;%First number = (1-1)*phi
while AF(a) > 2*pi
AF(a) = AF(a) - 2.*pi;
if AF(a)<= 2*pi;break;end
end %minimize the data if it is larger than 2pi
while AF(a) < -2*pi
AF(a) =AF(a) + 2*pi;
if AF(a) >= -2*pi;break;end
end %maximize the data if it is smaller than -2pi
end%does not affect the result but mitigate the calculation
as = AF(2)+AF(3)+AF(4)+AF(5)+AF(6)+AF(7)+AF(8)+AF(9);%weights in total
for th =1:360 %angle from 1 to 360
s = 0
angle_1rad(th) = th.*pi/180;%angle to radian
for i = 1:N
s = s + exp((-1j).*k.*(i-1).*d.*sin(angle_1rad(th))+as)%equation for field
end
f(th)= abs(s);
end
M = max(f);
z = f./M;%normalize the data
figure
polarplot(angle_1rad+as,z);
%title('linear polar plot');
ZIYI WENGhttps://se.mathworks.com/matlabcentral/profile/authors/13816818tag:se.mathworks.com,2005:Question/7536242021-02-23T10:35:25Z2021-05-08T06:37:45ZCreate a excel file (named as Input) in Matlab App designer and write variables in it. Respected All,
I want to create an excel file with "named as the input", and pass on variables into it from the app designer.
Aim is to create a file named "Test.xlsx" in the folder "Excel_Folder" and write variables "variable1", and "variable2" into the excel file after pressing the "Export data" pushbutton.
I have tried the following:
% Value changed function: NameEditField
function NameEditFieldValueChanged(app, event)
value = app.NameEditField.Value;
end
% Button pushed function: ExportdataButton
function ExportdataButtonPushed(app, event)
folder = app.Excel_Folder; % create a new folder with name Excel_Folder
filename = app.NameEditField.Value; % name of the file
writetable(fullfile(folder, filename), app.variable1, app.variable2); % write variables 1 and 2 into in the file
end
The above is neither creating a file in the folder nor displaying any error.
Thanking You.
Ajiket
Ajiket Patilhttps://se.mathworks.com/matlabcentral/profile/authors/15912563tag:se.mathworks.com,2005:Question/1073982013-11-25T01:58:39Z2021-05-08T06:37:15ZConvert from Rows to Column in MatlabI wanted to convert a table data as: 24 hours (24 column), and 30 day (31 rows) become 1 column which with continue hours from 1-24 for the first day and for the second day so on.`
day/hours: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
1 A B C ........................................................
2 A'B'C'.....
...
31
Become
________________
day1/1hour A
day1/2hour B
day1/3hour C
..........
day2/1hour A'
day2/2hour B'
....
day31/1hour A'''
day31/2hour B'''
day31/24hour Z''''dauhttps://se.mathworks.com/matlabcentral/profile/authors/4708854tag:se.mathworks.com,2005:Question/8239452021-05-07T07:44:07Z2021-05-08T06:34:20ZHow to Compute Cartesian to Polar If the ThetaZeroLocation on Top ?Hello, like the title of this question, i need to compute a Cartesian Points to Polar Point if the ThetaZeroLocation is on top.
Im using the code :
r = sqrt(x^2+y^2) %for rho
t = atan(y/x) %for theta
even im using this code :
t = atan2(y/x)
and
[theta,rho] = cart2pol(x,y)
the answer is still wrong. The value on rho or r is right ( but its has little different ) but the value on t or theta is wrong.
for example the data is
x = -0.00781250;
y = -9.593750000000000
so the real answer is
r = 9.605468750000000
t = 1.801263427734375e+02 % == 180.126
but i get this if im using the first code
r = 9.5938
t = 1.5700
and with the cart2pol
rho = 9.5938
theta = -1.5716
i get this data pair each other so i know the real value.
The polar graphic that i use is like this :
as you can see the zero theta location is on top and its clockwise. so how do i can compute it ?
NB : im sorry if my english is badZaidan Adenin Saidhttps://se.mathworks.com/matlabcentral/profile/authors/16527331tag:se.mathworks.com,2005:Question/465562012-08-23T08:35:27Z2021-05-08T06:31:26ZVector VN1610 and CANTool?Hello,
I have a Vector VN1610 USB Interface and i try to connect it to the CANTool to track the CAN messages without success. I have followed the "Hardware Devices and Drivers" installation steps http://www.mathworks.de/help/toolbox/vnt/ug/br2lgng-1.html#br2lgng-3 , but I only can see the Vector Virtual Channel 1 and 2. Does anyone know a way to connect the VN1610 device to Matlab?
regards
AndreasAndreashttps://se.mathworks.com/matlabcentral/profile/authors/3586108tag:se.mathworks.com,2005:Question/8242902021-05-07T14:29:21Z2021-05-08T06:30:50ZIs there a way to viewmark as images?Any possible way to extract viewmarks from Simulink as images?madhan ravihttps://se.mathworks.com/matlabcentral/profile/authors/12308260tag:se.mathworks.com,2005:Question/8247102021-05-08T01:52:16Z2021-05-08T06:30:37ZGet indices of all rows containing a value - repeated or notSay I have the following
id = (1:5)';
rng(1);
x = randperm(10,5)';
y = randperm(10,5)';
nodes = table(id,x,y)
connections = [1,2 ; 1,3 ; 2,4 ; 2,5 ; 3,5]
nodes =
5×3 table
id x y
__ _ _
1 3 6
2 4 2
3 7 5
4 1 3
5 2 1
connections =
1 2
1 3
2 4
2 5
3 5
I want to find the distances between the node pairs mentioned in connections (like between nodes 1 and 2, nodes 1 and 3, etc), based on their (x,y) values given in nodes table. And since the original data I have contains about 85000 connections, I'm looking to do this more efficiently than using a for loop for every pair. It works in the following way when the connections are unique:
connections = [1,3 ; 4,5];
x1 = nodes.x(ismember(nodes.id,connections(:,1)));
x2 = nodes.x(ismember(nodes.id,connections(:,2)));
y1 = nodes.y(ismember(nodes.id,connections(:,1)));
y2 = nodes.y(ismember(nodes.id,connections(:,2)));
% Chebyshev distance
dist = max([abs(x2-x1),abs(y2-y1)],[],2);
dist =
4
2
Thus, distance between nodes 1 and 3, and nodes 4 and 5, is 4 and 2 respectively. How can I do this as efficiently when there are repeated nodes in connections array? In the original case, I believe I should get
dist =
4
4
3
2
5
Tejashttps://se.mathworks.com/matlabcentral/profile/authors/18205581tag:se.mathworks.com,2005:Question/8247152021-05-08T02:03:56Z2021-05-08T06:29:03ZHello, everyone, as shown in the figure below, how to use the tangent L of point A as the y'axis direction, and the direction perpendicular to the y'axis as the x'axis. Establish such a coordinate system to facilitate local analysis.Wesleyhttps://se.mathworks.com/matlabcentral/profile/authors/19428999tag:se.mathworks.com,2005:Question/1252902014-04-10T15:43:24Z2021-05-08T06:27:43ZProblems with Common Spatial Pattern(CSP-Algorithm)Hello,
I downloaded the dataset(Dataset1) from BCI competition IV and trying to apply Common Spatial Pattern(CSP). I separated the two data set into two classes (class1 and class2). I passed them through CSP.m file and got the output as 59*59 matrix. I took first column representing as class1 and last column representing as class2 and then classified them but shockingly i got only 59% classification.I have attached CSP.m.
Cant figure out what mistake I have made.Could anyone help me out please.thanks in advance
Regards,sriharshahttps://se.mathworks.com/matlabcentral/profile/authors/2493991tag:se.mathworks.com,2005:Question/5802632020-08-16T12:28:49Z2021-05-08T06:25:00ZMatrix Determination Issue in getting hidden inputsWe had given a code ro write an Octave code to find the product of two matrices A and B, element-wise, and then reverse the rows.
Print them, and then find the determinant of the resulting matrix. Below is one of custom inputs which are visible to us, rest does not.
3
3
1 2 3
2 3 4
1 3 5
2 3 4
1 3 5
4 5 6
Sample Output:
Reversed_Matrix = 4 15 30
2 9 20
2 6 12
Determinant = 12
The first and second row denote the dimensions of the first and second square matrices. The next three rows denote the values in the first matrix, and the last three rows denote the values of the next matrix.
We written code as below which is correct, but we do not want it to be hard coded value, it pull it from custom input as mentioned above, please help how to remove value input as hard coded i.e. value which we providing in Reversed_Matrix. This we asking because we have 4 test case. For 1 we can see input, hence as per it we developed code, for rest 3 were not know what will be input hence do not want not any hard code input.
We are getting same output for test 1 but other 3 hidden test cases failled.
function matr()
Reversed_Matrix= flip([1 2 3; 2 3 4 ; 1 3 5].* [2 3 4; 1 3 5; 4 5 6])
Determinant= det(Reversed_Matrix)
endfunction
matr()Ashish Jindalhttps://se.mathworks.com/matlabcentral/profile/authors/19205124tag:se.mathworks.com,2005:Question/8248202021-05-08T06:16:30Z2021-05-08T06:16:30ZHow can I give a rotational velocity to spheres?t = linspace(0,6,250);
x1 = 0;
x2=2.01;
y = 0;
z = 0.234778*t;
figh = figure;
for k=1:length(t)
clf
t_k = t(k);
z_k = z(k);
[X,Y,Z] = sphere;
X2 = X ;
Y2 = Y ;
Z2 = Z ;
s=surf(X2,Y2,Z2+z_k);
[X,Y,Z] = sphere;
X2 = X;
Y2 = Y;
Z2 = Z;
sg=surf(X2+2.01,Y2,Z2+z_k);
grid on
xlabel('x')
ylabel('y')
zlabel('z')
xlim([-2.7 3.2])
ylim([-2.8 2.5])
zlim([0 3.9])
title(['t = ',num2str(t_k)])
view([30 35])
movieVector(k) = getframe;
end
so, this is my code for two sphere located in xy plane translating in z direction, now i want the spheres to rotate along y axis with some constant speed, how can I do that? what lines of I should add? Rishabh Katiyarhttps://se.mathworks.com/matlabcentral/profile/authors/15995916tag:se.mathworks.com,2005:Question/8243652021-05-07T15:31:38Z2021-05-08T06:07:51ZHow to tell matlab that y is a function of x; not a constantI have a function z such that z=xy(x) , [i.e. y is a function of x]. So if I differentiate z with respect to x, I shoud get dz/dx= y+x*(dy/dx). However if I use diff(z,x) in matlab, I get only y [matlab treats y as a constant]. What should I do to define y as a function of x?
syms x y z
z=x*y;
diff(z,x)
ans =
yAyan PATSAhttps://se.mathworks.com/matlabcentral/profile/authors/22390279tag:se.mathworks.com,2005:Question/8058812021-04-18T18:39:46Z2021-05-08T06:04:00ZHow can I gradient the legend color in MATLAB?I have a 3D-bar MATLAB code which represents data for 3-folds, as shown in the attached figure.
How can I gradient the legend color, ranging from #FFFF00 to #F68C00 and from #00FEEF to #3092E3, as shown in the big red box?
Amal AbdelGawadhttps://se.mathworks.com/matlabcentral/profile/authors/16896516tag:se.mathworks.com,2005:Question/81382011-05-25T05:10:35Z2021-05-08T06:00:26ZHow to convert an image into a binary stream of data? How to convert an image into a binary stream of data? Is there any Built in function to do that?
Thanks in AdvanceUbaid Ullahhttps://se.mathworks.com/matlabcentral/profile/authors/2878121tag:se.mathworks.com,2005:Question/8248102021-05-08T05:48:20Z2021-05-08T05:50:14ZHow can I solve this symbolic inequality and get a parametric answer?Hello everyone.
I'm really new to using matlab, so I apologize for the question which may look stupid but I have problems in solving inequalities with Matlab.
Specifically, I wanted to solve for n in the following inequality
power(2,k)<=power(2,n)/[symsum(factorial(n)/factorial(i)*factorial(n-i),i,0,1)]
I don't really know how or is it even possible or if I used the functions that I looked up correctly(i.e. power,factorial)
I did try solving the inequality with k=16 because I know the answer for this case is n>=21,
syms n
solve(power(2,16)<=power(2,n)/symsum(factorial(n)/factorial(i)*factorial(n-i),i,0,1),n)
but I got an error for using factorial(n), warning me that N must be a non-negative real integer array.
:(
Thank you for any kind help
Xuanhan 朱https://se.mathworks.com/matlabcentral/profile/authors/19125213tag:se.mathworks.com,2005:Question/8247752021-05-08T04:07:31Z2021-05-08T05:46:21ZPlotting y=sin x in 3dI want to plot y=sin x,0≤ x ≤ 2π, with 300 linear space points interval in 3D. Im kinda new to matlab, so i the read help center to learn how to do plot 3d graph. Can someone help me check it if it correct or not?
x=linspace(0,2*pi,300);
[x,y]=mehsgrid(x);
z=sin(x);
surf(x,y,z)Amril Luqmanhttps://se.mathworks.com/matlabcentral/profile/authors/21868416tag:se.mathworks.com,2005:Question/8248002021-05-08T05:35:23Z2021-05-08T05:35:23ZHow can i do "code capture" in Simbiology of MATLAB 2020b version?Hi, I'm currently on a project to make a calculating doses GUI.
I need to link the GUI with the model in simbiology I've built. I've also searched how to do that and I saw the 'code capture' tools. Nevertheless, I couldn't find that in the current matlab version I used, please help where could I found these tools?Farah Fauziah Arditamihttps://se.mathworks.com/matlabcentral/profile/authors/19126801tag:se.mathworks.com,2005:Question/8247202021-05-08T02:18:47Z2021-05-08T05:33:54ZCan anyone explain the following code?%% Vibration of nomex honeycomb sandwich structure
%=============================================================================
clear all % To clear all variables
close all % To close all windows
clc; % To clear the screan
%=============================================================================
%% Pre-Processor
%=============================================================================
% Geometrical Properties
L=0.25; % Length of the beam in meters
B=0.03; % Breadth of the beam in meters
t=0.25e-3; % Thickness of each lamina in meters
tc=2e-3; % Thickness of nomex honeycomb
%==============================================================================
% Material Properties (All units are in SI)
% =======================
% Face Sheet properties
%========================
E1=70e9; % Youngs modulus in direction 1
E2=6e9; % Youngs modulus in direction 2
G12=3.2e9; % shear modulus in the plane 12
v12=0.22; % poisson ratio in the plane 12
rho=1627;
theta=[0 90 90 0]*(pi/180); % Ply angle of face sheet
N=size(theta,2);
d=tc+N*t;
e=d/tc;
% ===================================
% Nomex honeycomb material properties
%===================================
Ecm=0.9e9;
Gc=0.32e9; % shear modulus in the plane 12
rhocm=724;
wt=0.063;
wl=3.2;
% ===================================
% Nomex honeycomb properties
%====================================
Gc13=(5/(3*sqrt(3)))*(wt/wl)*Gc;
Ec1=(4/sqrt(3))*(wt/wl)*Ecm;
rhoc=(2/sqrt(3))*(wt/wl)*rhocm;
%================================
%ABD Matrix
%--------------------------------
% Compliance matrix
%--------------------------------
s = [1/E1 -v12/E1 0 ;
-v12/E1 1/E2 0 ;
0 0 1/G12;];
%-----------------------------------
% ABD and I matrix
%-----------------------------------
Q1=s\eye(3);
A1=0;
B1=0;
D1=0;
I0=0;
I1=0;
I2=0;
Zk =t*(0-N/2);
for i1=1:N
teta=theta(i1);
T = [ cos(teta)^2 sin(teta)^2 -2*sin(teta)*cos(teta) ;
sin(teta)^2 cos(teta)^2 2*sin(teta)*cos(teta) ;
cos(teta)*sin(teta) -cos(teta)*sin(teta) cos(teta)^2-sin(teta)^2;];
Q = T*Q1*transpose(T) ;
Zk1 = t*(i1-N/2);
A1 = A1+Q(1,1)*(Zk1-Zk);
B1 = B1+(1/2)*Q(1,1)*(Zk1^2-Zk^2);
D1 = D1+(1/3)*Q(1,1)*(Zk1^3-Zk^3);
I0 = I0 + (rho)*(Zk1-Zk);
I1 = I1 + (1/2)*(rho)*(Zk1^2-Zk^2);
I2 = I2 + (1/3)*(rho)*(Zk1^3-Zk^3);
Zk = Zk1;
end
[ABD]=[A1 0 B1;
0 A1 B1;
B1 B1 2*D1;];
[I] =[I0 0 I1;
0 I0 I1;
I1 I1 2*I2;];
I0c = rhoc*tc;
%==============================================================================
% Meshing
%==============================================================================
Nel=100; % No. of Elements
Le=L/Nel; % Length of the element
nodes=Nel+1; % Total no. of nodes
dof=4; % degrees of freedom per node
sdof=nodes*dof; % System degrees of freedom
nnodes=1:nodes; % Numbering of nodes
xcoord=Le*(nnodes-1);
% ===========================================================================
% boundary conditions
% ===========================================================================
bc=[1 2 3 4]; % Cantilever beam
% bc=[1 2 3 4 4*nnodes(end)-3 4*nnodes(end)-2 4*nnodes(end)-1 4*nnodes(end)]; % Fixed beam
% bc=[1 2 3 4*nnodes(end)-3 4*nnodes(end)-2 4*nnodes(end)-1]; % Simply supported beam
%=============================================================================
%% Processor
%=============================================================================
% initilization of Global Stiffness and Mass matrix
K=zeros(sdof); % Global stiffness Matrix;
M=zeros(sdof); % Global Mass Matrix;
%=================================================================
% Gauss points for numerical Integration
zeta=[-1/sqrt(3) 1/sqrt(3)];
gw=[1 1];
[N1dbar, N1dbeam]=shapeFn1db(zeta,Le); % Shape function values at gauss point
[dN1dbar, dN1dbeam]=dshapeFn1db(zeta,Le); % differentiation of shape function values at gauss point
[ddN1dbeam]=ddshapeFn1db(zeta,Le); % double differentiation of shape function values at gauss point
%=================================================================
Kel=zeros(2*dof); % Element stiffness matrix
Mel=zeros(2*dof); % Element mass matrix
for i2=1:Nel
conn=[nnodes(i2) nnodes(i2+1)]; %connectivity Matrix
index=[4*(conn(1)-1)+1 4*(conn(1)-1)+2 4*(conn(1)-1)+3 4*(conn(1)-1)+4 4*(conn(2)-1)+1 4*(conn(2)-1)+2 4*(conn(2)-1)+3 4*(conn(2)-1)+4];
xgp(i2,:)=xcoord(conn)*N1dbar;
for i3=1:size(zeta,2)
J=dN1dbar(:,i3).'*xcoord(conn).';
dN1dbar=(1/J)*dN1dbar;
dN1dbeam=(1/J)*dN1dbeam;
ddN1dbeam=(1/J^2)*ddN1dbeam;
Bb1=[dN1dbar(1,i3) 0 0 0 dN1dbar(2,i3) 0 0 0;
0 dN1dbar(1,i3) 0 0 0 dN1dbar(2,i3) 0 0;
0 0 ddN1dbeam(1,i3) ddN1dbeam(2,i3) 0 0 ddN1dbeam(3,i3) ddN1dbeam(4,i3);];
S1=[N1dbar(1,i3) 0 0 0 N1dbar(2,i3) 0 0 0;
0 N1dbar(1,i3) 0 0 0 N1dbar(2,i3) 0 0;
0 0 dN1dbeam(1,i3) dN1dbeam(2,i3) 0 0 dN1dbeam(3,i3) dN1dbeam(4,i3);];
S2=[0 0 N1dbeam(1,i3) N1dbeam(2,i3) 0 0 N1dbeam(3,i3) N1dbeam(4,i3)];
S3=e*[N1dbar(1,i3)/d -N1dbar(1,i3)/d dN1dbeam(1,i3) dN1dbeam(2,i3) N1dbar(2,i3)/d -N1dbar(2,i3)/d dN1dbeam(3,i3) dN1dbeam(4,i3);];
B2=e*[N1dbar(1,i3)/d -N1dbar(1,i3)/d dN1dbeam(1,i3) dN1dbeam(2,i3) N1dbar(2,i3)/d -N1dbar(2,i3)/d dN1dbeam(3,i3) dN1dbeam(4,i3);];
B3=(1/2)*[dN1dbar(1,i3) dN1dbar(1,i3) 0 0 ddN1dbeam(2,i3) dN1dbar(2,i3) 0 0;];
% Kel=Kel+B*(Bb1.'*ABD*Bb1+B2.'*Gc13*tc*B2+B3.'*Ec1*tc*B3)*J*gw(i3);
Kel=Kel+B*(Bb1.'*ABD*Bb1+B2.'*Gc13*tc*B2)*J*gw(i3);
Mel=Mel+B*(S1.'*I*S1+S2.'*(2*I0+I0c)*S2+S3.'*(rhoc*tc^3/3)*S3)*J*gw(i3);
end
%------------------------------------------------------------------
%Assemble stiffness and Mass vector
%------------------------------------------------------------------
K(index,index)=K(index,index)+Kel;
M(index,index)=M(index,index)+Mel;
end
%% apply boundary conditions
K(bc,:)=[];
K(:,bc)=[];
M(bc,:)=[];
M(:,bc)=[];
%% Natural frequiencies
[eigvec,eigval]=eig(K,M);
nfrq=sort(sqrt(diag(eigval))); % natural frequencies in rad/s
natfre=(nfrq)/(2*pi); % natural frequencies in Hz/s
[lamda1,kn1]=sort(diag(eigval)); % to sort eigvector
eigvector=eigvec(:,kn1); % mode shpe
disp('First Five Natural Frequencies')
disp(natfre(1:5))
% mode shapes of cantelever beam
%--------------------------------------------------------------------------
K1=4;
ms=eigvector(3:4:end,K1);
ms=[0; ms;];
ms=(1/(max(abs(ms))))*ms;
x1=linspace(0,1,Nel+1);
plot(x1,ms,'r*-')
%--------------------------------------------------------------------------
% mode shapes of Fixed beam
%--------------------------------------------------------------------------
% K1=1;
% ms=eigvector(3:4:end,K1);
% ms=[0; ms; 0;];
% ms=(1/(max(abs(ms))))*ms;
% x1=linspace(0,1,Nel+1);
% plot(x1,ms,'r*-')
%--------------------------------------------------------------------------
% mode shapes of cantelever beam
%--------------------------------------------------------------------------
% K1=4;
% ms=eigvector(4:4:end,K1);
% ms=[0; ms; 0;];
% ms=(1/(max(abs(ms))))*ms;
% x1=linspace(0,1,Nel+1);
% plot(x1,ms,'r*-')
%----------------Aparna Adhikarihttps://se.mathworks.com/matlabcentral/profile/authors/13966799tag:se.mathworks.com,2005:Question/8247852021-05-08T04:23:47Z2021-05-08T05:27:24ZError using odearguments line doesn't exist.[T,Y] = ode45(@Bqfun1,[0 2],[1 1 -0.01]);
plot (T,Y(:,1),'b','linewidth',1)
function dy1 = Bqfun1(t,y)
dy1 = zeros(2,1);
dy1=[y(2)];
y(3)
-3*y(3)-3*y(2)-y(1)-4*sin(t);
end
Error using odearguments (line 95)
BQFUN1 returns a vector of length 1, but the length of initial conditions vector is 3. The vector returned by BQFUN1 and
the initial conditions vector must have the same number of elements.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in Test4 (line 1)
[T,Y] = ode45(@Bqfun1,[0 2],[1 1 -0.01]);
What the heck does this even mean? I dont have a line 95.David Scidmorehttps://se.mathworks.com/matlabcentral/profile/authors/19257228tag:se.mathworks.com,2005:Question/8245502021-05-07T19:43:40Z2021-05-08T05:18:51ZWhy this function infinity loop%It give an integer x which contains d digits, find the value of n (n > 1) such that
%the last d digits of x^n is equal to x. Example x=2 so n=5 because 2^5=32 and last
%digits of 32 is 2
%So why this take infinity loop
function n = bigNumRepeat(x)
d = length(num2str(x))
y=2
n=2
while 1
y = y*x
y = num2str(y)
y = str2num(y(end - d + 1:end))
if y==x
break
end
n=n+1
end
endNguyen Huyhttps://se.mathworks.com/matlabcentral/profile/authors/20326460tag:se.mathworks.com,2005:Question/8247402021-05-08T02:42:35Z2021-05-08T05:12:54ZCorrect Way To Code? Actually im very newbie but some of you in this community helps me a lot to make my own code.
im still confuse which situation i should use table,array or cell.I cannot understand well which type of data i should use.
but im very glad because I can learn some code and happy when I get expected result.
below is my problem.
This is some of my code.
and I have several question to ask.
%Create Combination
[a,b,c,d,e]=ndgrid(1:20,1:10,1:10,1:5,1:5);
data=[a(:),b(:),c(:),d(:),e(:)];
Above is my method to create possible pair.but can anyone help to make possible pair with other method?
so I dun need to convert many times when I need to do calculation.
ExpandData=[PV(data(:,1),:), Batt(data(:,2),:), MPPT(data(:,3),:), Inverter(data(:,4),:), DieselGenerator(data(:,5),:)];
%combination data like matrix using ndgrid as above generated 50000X24 cells
T10 = ExpandData(:,10)%AlphaPmp % have 50000x1 %data from above table column no 10
T11= ExpandData(:,10)%Tstc % have 50000x1 % %data from above table column no 11
AAlpha_pmp = cell2mat(T10)
Tstc= cell2mat(T11)
RawIrr = readtable("DataForLPSP.txt")
P1 = RawIrr (:,1)
P2= RawIrr (:,2)
P3 = RawIrr (:,3)
P5 = RawIrr (:,5)
Date = table2array(P1) 67707X1
Time = table2array(P2) 67707X1
AirTemp = table2array(P3) 67707X1
DNI = table2array(P5) 67707X1
FtempN = 1 + Alpha_pmp.* (AirTemp(:,1)' - Tstc);
Esys = table(char(T1),FtempN)
my intention is I want to get 50000 X 67707 result.but
my final output is :
PV2 [1x67707 double]
PV2 [1x67707 double]
PV3 [1x67707 double]
PV4 [1x67707 double]
PV5 [1x67707 double]
PV6 [1x67707 double]
PV7 [1x67707 double]
PV8 [1x67707 double]
why I dun get
PV 1 0.0323 0.23232 0.1456 0.1256 (this should expand until 67k column)
until
PV 20 0.0323 0.23232 0.1456 0.1256 (this should expand until 67k column)
and how to put DATE and TIME at the row 1 and 2 for this data.So I can refer which data to use in future.
and actually I want to make 400k X 105k data.because of 'Out Of Memory' I cut down the variable.
please someone help me.....Shahid Saidhttps://se.mathworks.com/matlabcentral/profile/authors/10579605tag:se.mathworks.com,2005:Question/8238352021-05-07T04:43:37Z2021-05-08T05:06:59Zhow to integrate a product with function handleI want to perform a numerical integration with function handle. Please find details below
Nz = 256;
L = 1;
dz = L/Nz;
zgrid = dz*(0:Nz-1)'-L/2;
gN = 20000;
U0 = 5*gN;
U1=1.9*gN;
sigma = 5*dz;
xb = L/4;
tau = 0.01;
h=0.2*gN;
n0=mean(dens(abs(zgrid)<L/10,:));
wp=2*pi*sqrt(gN*n0);
Ub = @(t) U1*(t<tau)+(t>=tau)*(U1+h*sin(wp*(t-tau)));
Vext = @(t) (U0*exp(-(zgrid+xb).^2/sigma^2)+Ub(t)*exp(-(zgrid-xb).^2/sigma^2));
Now I want to integrate
integrate (Vext *A, zgrid)
where A is a double array matrix of dimension (zgrid,t)
The problem is Vext is function handle and A is numerical values of the dimension (zgrid,t). please help how to do this integration? Abhik Sahahttps://se.mathworks.com/matlabcentral/profile/authors/18131504tag:se.mathworks.com,2005:Question/8247902021-05-08T04:54:58Z2021-05-08T05:05:19ZCan you guys help write a code for my machine problemWrite a script that will prompt the user to input a number from 1 – 9 only and display the
figure below.
Sean Russell Basaenhttps://se.mathworks.com/matlabcentral/profile/authors/21747220tag:se.mathworks.com,2005:Question/1147362014-02-04T06:33:45Z2021-05-08T05:02:30Zenergy of the image as the entropy of the image can be obtained by entropy filter as image ,can i get the image that shows the maximum energy pixels in the original gray image. kalaivaanihttps://se.mathworks.com/matlabcentral/profile/authors/4436603tag:se.mathworks.com,2005:Question/8247952021-05-08T04:59:33Z2021-05-08T04:59:33ZKp using known stedy state errorIs there a function for getting the value of Kgain if i am designing a system so its steady state error is 5%Ghaith Mustafahttps://se.mathworks.com/matlabcentral/profile/authors/22474877tag:se.mathworks.com,2005:Question/8241752021-05-07T12:21:10Z2021-05-08T04:53:09ZCan I speed up this matrix multiplication?Sorry for this stupid question. I know that the matrix multiplication has been highly optimized by Matlab, but I am still want to figure out that can I further speed up only for this special case?
I have no idea for this bottleneck in my code. The simplified code is uploaded in the following.
% X, Q are given symmetric matrix
[P, ~] = eig(X);
ans = P*(Q.*(P'*Y*P))*P'; % Y will change in each loop.
The X, Y, and Q are 1000x1000 matrices. In each loop, I have to compute four matrix multiplications,
But actually, P and Q are constant matrices in each loop, so I want to know what I could do to further speed up this code?
I have tried gpuArray, but it cannot be faster than normal Matlab * operation (maybe my GPU is not good enough..)
Any suggestion will be appreciated.Zenan Lihttps://se.mathworks.com/matlabcentral/profile/authors/15816199tag:se.mathworks.com,2005:Question/3317932017-03-24T18:20:31Z2021-05-08T04:37:42ZError in Simulink.messageviewer.internal.MsgIdToDataMap/addRecord - Caused by: Maximum recursion limit of 500 reached.Hello,
I have recieved the following error message:
"Error in Simulink.messageviewer.internal.MsgIdToDataMap/addRecord
Caused by:
Maximum recursion limit of 500 reached."
Or I will also (for no reason I have figured out yet) recieve
"Warning: The following error was caught while executing 'slmsgviewer' class destructor:
Maximum recursion limit of 500 reached.
Error in slmsgviewer
Caused by:
Maximum recursion limit of 500 reached. "
in mass on my command prompt. This occurs when I open a simulink file that has a distribution system (power system) set up. I am not running any simulations or anything yet I am simply opening the file.
I cannot find information on how this could trigger a maximum recursion limit from opening a simulink/simscape power systems file or where/what the Simulink.messageviewer.internal.MsgIdToDataMap/addRecord' is.
I have:
1) changed the blocks which are put in the system so that I know its not an issue with callbacks or initialization in the masking
2) commented out code which initializes the block parameters from the code (File is initially populated with blocks from code)
3) deleted sections of blocks to find if is a specific problem with one (its not at about 20/50 blocks the error message stops but it doesnt matter which blocks are deleted)
I do not have the first idea about what I am dealing with and despite many hours searching google, Matlab Wiki and even youtube.
The only solutions I have seen so far make no mention of this happening in a simulink/simscape file and usually advise to just increase the recursion limit. I would like to know what the issue is though to properly solve it.
Any information on this will be greatly appreciated.
Thank you for your time.Tarek Bos-Jabbarhttps://se.mathworks.com/matlabcentral/profile/authors/9597702tag:se.mathworks.com,2005:Question/8246552021-05-07T23:28:30Z2021-05-08T04:33:08ZApply a change on all the double variables of a .mat file at onceHello,
Do you have any idea on how I can apply a change on all the double variables of a .mat file at once.
The change will be a shift of 4 elements, example:
(A, B and C are variables in the .mat file)
A_before = [1 2 3 4 5]; => A_after = [0 0 0 0 1 2 3 4 5];
B_before = [11 22 33 44 55]; => B_after = [0 0 0 0 11 22 33 44 55];
C_before = [111 222 333 444 555]; => C_after = [0 0 0 0 111 222 333 444 555];
The first .mat file contains a hundred variables, and another .mat file which contains a structure of 200 variables.
How to apply this recalibration to all the variables in the .mat file at once.
Thanks
amakoba yimhttps://se.mathworks.com/matlabcentral/profile/authors/22408851tag:se.mathworks.com,2005:Question/8246102021-05-07T21:38:31Z2021-05-08T04:29:43Zgetting numbers from a cellI want to get the numbers from the cell below and have them as a Matrix:
A =
'1.39675e-02 -2.58099e-01 -8.32728e-03 0.00000e+00 2.19518e+01 1.21930e-01 0.00000e+00 3.00000e-05 3.00000e+02 9.98200e+02 1.41117e-11 'M Reza Zharfahttps://se.mathworks.com/matlabcentral/profile/authors/19091950tag:se.mathworks.com,2005:Question/8206202021-05-03T16:26:59Z2021-05-08T04:26:23Zimport data from word to MATLAB and save to other word file?Hi,
I have two word files, one contains figures and their figure no.s and other word file contains tables. I want to read these two file's data into matlab and save both data in other word file?garima sharmahttps://se.mathworks.com/matlabcentral/profile/authors/19303396tag:se.mathworks.com,2005:Question/5082652020-02-29T15:17:27Z2021-05-08T04:22:51ZCreate a single average day out of hourly data (33days)?How am I able to sum my hourly data to create one "typical/average" day (diurnal cycle) out of 33 days.
I'm using 2017b and stored my data in a timetable using retime() to story hourly means
First row is date second is hourly mean temp.
'07-Mar-2019 11:00:00' 16
'07-Mar-2019 12:00:00' 14
'07-Mar-2019 13:00:00' 12
'07-Mar-2019 14:00:00' 19
'07-Mar-2019 15:00:00' 23
'07-Mar-2019 16:00:00' 14
'07-Mar-2019 17:00:00' 15
'07-Mar-2019 18:00:00' 18
'07-Mar-2019 19:00:00' 17
'07-Mar-2019 20:00:00' 13
'07-Mar-2019 21:00:00' 14
'07-Mar-2019 22:00:00' 14
'07-Mar-2019 23:00:00' 15
'08-Mar-2019 00:00:00' 16
'08-Mar-2019 01:00:00' 15
'08-Mar-2019 02:00:00' 13
'08-Mar-2019 03:00:00' 12
'08-Mar-2019 04:00:00' 16
'08-Mar-2019 05:00:00' 12
'08-Mar-2019 06:00:00' 12
'08-Mar-2019 07:00:00' 12
Matlab 2019 has groupsummary() which might do my job....
Martin Muehleggerhttps://se.mathworks.com/matlabcentral/profile/authors/16924403tag:se.mathworks.com,2005:Question/8246352021-05-07T22:52:40Z2021-05-08T04:18:39ZError in odearguments (line 87) f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0. Error in ode45 (line 115) odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin); Error in untitled2 (line 6) [z, v]=ode45(@chpHow can I fix this error?
script:
Fclear
clc
%adibatic
v0=[0 305];
zspan=[0 10];
[z, v]=ode45(@chp12ex7_b, zspan, v0);
Cao=0.1; dH=-6000;
X = v(:,1); T = v(:,2);
k=0.01.*exp((5033)*(1/300-1./T)); Kc=10.*exp((dH./1.987)*(1/450-1./T));
Xeq=(2.*Cao.*Kc+1-sqrt(4.*Cao.*Kc+1))./(2.*Cao.*Kc);
rate=-k.*((Cao.^2)*((1-X).^2)-Cao.*X./Kc);
plot(z, v(:,1), z, Xeq), xlabel ('Volume (dm^3)'), ylabel ('Conversion'), legend('X','Xe'), title('Adiabatic')
figure
plot(z, v(:,2)), xlabel ('Volume (dm^3)'), ylabel ('Temperature'), legend('T'), title('Adiabatic')
figure
plot(z, -rate, 'k-'), xlabel ('Volume (dm^3)'), ylabel ('rate'), title('Adiabatic')
function:
function ydot = chp12ex7_b(~,~,y)
%input variables
X=y(1); T=y(2);
%data
Ua=0; Cao=0.1; Fao=0.2; dH=-6000; Cpo=30; Ta = 0;
%rate
k=0.01*exp((5033)*(1/300-1/T)); Kc=10*exp((dH/1.987)*(1/450-1/T));
rate=-k*((Cao.^2)*((1-X).^2)-Cao.*X./Kc);
%Equations
ydot(1)=-rate/Fao; ydot(2)=((rate*dH)-Ua*(T-Ta))/(Cpo*Fao);
ydot=ydot';
end
Tracy Tetzloffhttps://se.mathworks.com/matlabcentral/profile/authors/21298376tag:se.mathworks.com,2005:Question/8247552021-05-08T03:05:58Z2021-05-08T04:06:51ZPlotting a filter as a function of cyclic frequency using freqz()Hello,
I'm trying to graph a moving average filter's magnitude response as a function of cyclic frequency. However, when I use freqz(), my plots do not look correct. Here's my code currently:
clear;close all;
fs = 200; %sampling frequency
Ts = 1/200; %sampling time
t = 0:Ts:1;
x = sin(2*pi*2*t) + sin(2*pi*10*t) + sin(2*pi*90*t); %signal
figure(1)
plot(t,x); %unfiltered signal
title('Signal with 2, 10, and 90 Hz');
xlabel('time (s)');
%Difference equation of Hanning Moving Average filter:
yn = zeros(size(t));
ind = 3:length(t);
yn(ind) = (0.25*x(ind)) + (0.5*x(ind-1)) + (0.25*x(ind-2));
%Attempt at creating the moving average equation.
figure(2)
plot(t,yn)
title("Hanning Moving Average")
%Me just plotting the filtered Hanning Moving Average plot with
%freqz():
figure(10)
freqz(yn)
Both the magnitude (dB) and the phase seem to show a lot of sound, but the plot of figure 2 does not. Any help will be appreciated.Terry Carneyhttps://se.mathworks.com/matlabcentral/profile/authors/16179111tag:se.mathworks.com,2005:Question/8247702021-05-08T04:06:27Z2021-05-08T04:06:27ZSimulation of differential equations with multiple variables. BiotechnologyI want to simulate those differential equations and compare them with the values of X, P, S
my error: Array indices must be positive integers or logical values.
Error in @(t,a)[(umax(1-(a(3)/pmax)^n))*a(1);-((umax(1-(a(3)/pmax)^n))*a(1))/(yxs);ypx*((umax(1-(a(3)/pmax)^n))*a(1))]
function pos = paramfun1(x,tspan)
umax = x(1);
ypx = x(2);
yxs = x(3);
pmax = x(4);
xt0 = x(0.05,47,0);
f = @(t,a) [(umax(1-(a(3)/pmax)^n))*a(1);-((umax(1-(a(3)/pmax)^n))*a(1))/(yxs);ypx*((umax(1-(a(3)/pmax)^n))*a(1))];
[~,pos] = ode45(f,tspan,xt0);
B = [0.05,0.07,0.15,0.25,0.32,0.42,0.6,0.93,1.3,1.57,1.75,1.9]';
S = [47,76,45,42,40,35,28,21,9,2,0]';
P = [0,1,2,4,6,11,17,23,34,41,42,42]';
t = [0,2,4,6,8,10,12,14,16,18,20,22]'
umax = 0.33;
ypx = 0.90;
yxs = 0.0343;
pmax = 122.22;
n = 1.88;
%a(1) = x
%a(2) = s
%a(3) = p
f = @(t,a) [(umax(1-(a(3)/pmax)^n))*a(1);-((umax(1-(a(3)/pmax)^n))*a(1))/(yxs);ypx*((umax(1-(a(3)/pmax)^n))*a(1))];
xt0 = [0.5,47,0];
[tspan,a] = ode45(f,[0 47],xt0);
plot(tspan,a(:,1),tspan,a(:,2),tspan,a(:,3),t,[B,S,P],'o-')
title('Modelado Matemático: Levenspiel')
xlabel('Tiempo en hrs')
ylabel('Biomasa (X), Sustrato (S),Producto (P)')
hold offAdam Andersonhttps://se.mathworks.com/matlabcentral/profile/authors/22474442