https://nl.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2019-02-19T16:48:06Ztag:nl.mathworks.com,2005:Question/4458252019-02-19T14:44:12Z2019-02-19T16:48:06ZHow to modify this code to make it import values from a file?Hi,
The following code opens a file (named "Pulse.acc") and writes c, s and t values as follows:
0 1 0
0 2 0
0 3 0
It also opens another file (named :Case.tcl") and writes each case number.
Each case over-writes the previous one.
I am now trying to import the values of s from the attached file (named "result_40.txt"). This file contains 40 columns and 10 rows. Each value in the columns will be printed in "Pulse.acc" file and excute OpenSees software model (along with c and t values. For example: 0 1 0, as shown above). This needs to continue until the 10th value in the column. Then, the second column starts.
The values of c and t will continue to be zero, so they could be left as below.
It would be great if a folder can be opened for the outputs from each column and numbered sequentially.
I hope I could explain what I want clearly, and please feel freel to let me know if I need to explain it further.
c=[0 0 0];
s=[1 2 3];
t=[0 0 0];
for j = 1:3
fidP = fopen('Pulse.acc','w+');
fidC= fopen('Case.tcl','w+');
fprintf(fidP, '%d\n%d\n%d',c(j), s(j), t(j));
fprintf(fidC, 'set case %d',j);
fclose(fidP);
fclose(fidC);
!OpenSees Model.tcl
endIsmail Qeshtahttps://nl.mathworks.com/matlabcentral/profile/authors/10292327-ismail-qeshtatag:nl.mathworks.com,2005:Question/4458532019-02-19T16:39:38Z2019-02-19T16:44:22Ztfest() function using - set initial condition for output valueGood day
Could you help me please to figure out if i have an opportunity to set initial conditions of output signal for estimated transfer function?
I'm trying to estimate a TF based on data above: input signal is orange one, output signal is blue one. The yellow one is what i get, if i set the input signul to estimated TF.
If i substract from my real output value the initial point (the value is 511), the the estimation goes well and i got good result. But as i understand it would be the wrong TF
I know that we can set the initial value of input signal, but do we have an oppotrunity to do it for output? Alex Typakinhttps://nl.mathworks.com/matlabcentral/profile/authors/12732675-alex-typakintag:nl.mathworks.com,2005:Question/4458552019-02-19T16:43:34Z2019-02-19T16:43:34Zpicking those matrices whose determinant is greater than 0I have many matrices and I need to pick only those matrices whose determinant is greater than zero. For instance, consider the simple code which generates 4*4 matrices and evaluate its determinant. How can i show just those matrices whose determiant is greater than zero.
x(1)=2;
y(1)=3;
z(1)=-1
for i=1:15
x(i+1) = 2*x(i);
y(i+1) = 3*y(i);
z(i+1) = -2*z(i);
end
k1 = reshape(x,4,4)
k2 = reshape(y,4,4)
k3 = reshape(z,4,4)
d = det(k1)
d = det(k2)
d = det(k3)
Any help will be appreciated.tanveer haqhttps://nl.mathworks.com/matlabcentral/profile/authors/13868209-tanveer-haqtag:nl.mathworks.com,2005:Question/3666692017-11-13T05:00:24Z2019-02-19T16:43:17ZHow to view images from .mha and .mat file format?i download brain tumor data set from <https://figshare.com/articles/brain_tumor_dataset/1512427> in .mat file format and from BRATS 2015 in .mha file format, but because am new to MATLAB i can't able to see the images, can anyone help me?
thank you Melaku Eneayehuhttps://nl.mathworks.com/matlabcentral/profile/authors/10101131-melaku-eneayehutag:nl.mathworks.com,2005:Question/4458542019-02-19T16:42:24Z2019-02-19T16:42:24ZImporting .snp filesHow can I import the values from a .snp file and use them?Bidisha Barmanhttps://nl.mathworks.com/matlabcentral/profile/authors/14762087-bidisha-barmantag:nl.mathworks.com,2005:Question/4458302019-02-19T15:03:51Z2019-02-19T16:42:23ZHow can I display a value of a vector for a specific value? I have two vectors:
p = [5 0 6 7 0];
w = [6 2 5 6 7];
How can I display in matlab that for every 0 in vector p, the program shows me the two elements in w, namely w1 = 2 and w2 = 7? ntclrzhttps://nl.mathworks.com/matlabcentral/profile/authors/13939276-ntclrztag:nl.mathworks.com,2005:Question/4458512019-02-19T16:37:58Z2019-02-19T16:42:01ZHow can i reduce precision only in the maximum value of a column matrix?I would like to reduce the precision only to the maximum value of my matrix D3 (attached). All the values are with 4 decimals but i want the maximum with only two decimals, rounded down.
Thanks in advance Elisa Mammolitihttps://nl.mathworks.com/matlabcentral/profile/authors/11936937-elisa-mammolititag:nl.mathworks.com,2005:Question/4457662019-02-19T09:46:39Z2019-02-19T16:41:23ZHow to save images as jpgs from .mat files structHi ,I have 3064 .mat files dataset of brain tumors ,Prepareing data with lables for CNN.Each .mat file has struct 1x1 . Struct has following has these information: cjdata.image and cjdata.label.
And image is stored as cjdata.image.
I want to load all the .mat files:
1.mat ,2.mat ,3.mat ........................3064.mat
Want to apply these three opertions on each .mat file iteratively using a loop
1- accessing image from struct
2.convert into gray scale
3.save grayscale image as as 1.jpg 2.jpg.....3065.jpg
% Reading folder that has 3064 .mat files
myFolder = 'C:\Users\join2\Desktop\FIGSHARE\figshare data progress\figshare jpg data\3064 images';
filePattern = fullfile(myFolder, '*.mat');
Pgraymap = dir(filePattern);
for I = 1:length(Pgraymap)
baseFileName = Pgraymap(I).name;
str = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', str);
img1 = imread(str); % new
% load .mat
d=load(filePattern);
% acessing images from .mat files. each .mat has image as strcture,that
% is "cjdata.image"
d.cjdata.image;
% gray scale conversion
d=im2uint8(d);
% save all d.cjdata.image as jpgs in myFolder .plz help i don't know how to save
endMamoona Nisarhttps://nl.mathworks.com/matlabcentral/profile/authors/13592790-mamoona-nisartag:nl.mathworks.com,2005:Question/4456112019-02-18T16:23:29Z2019-02-19T16:41:19ZProblem of integration, the code run but the solution is not satisfying Hi all! I coded the Eq.C.4 to find η(t) and the code works, but, as you can see from the fig. attached, my solution does not match with the one proposed by a scientific paper for the same equation and input data. Any suggestions?
Roi=916;
Row=1024;
R=Row/Roi;
r=50;
d=50;
%column geometry
H0=50;
l=5;
b=5;
a=(2*l*H0/pi)^0.5;
Area=pi*a^2;
Vol=Area*H0;
%Dinamic of the block
Omega=1;
va=(3*(pi)^(3/2))/(16*sqrt(2))*(Omega*sqrt(l*H0))/(1+pi/4*R*(l/b));
%Surfaceelevation
E=zeros(1,301);
t=0:0.1:30;
for i=1:301
O=@(x,y)(besselj(0,x.*y.*a/d)).*((1-y.^2).^0.5).*y.*besselj(0,x*r/d).*((x.*tanh(x)).^0.5).*sin((((9.81/d*t(i).^2).*x).*tanh(x)).^0.5).*x;
E(i)=integral2(O,0,2000,0,1,'Method','iterated','AbsTol',1e-10,'RelTol',1e-10)
end
E1=-2*(a.^3)/(d^3.5)/(9.81^0.5)*va*d*E;Tommaso Attilihttps://nl.mathworks.com/matlabcentral/profile/authors/14259428-tommaso-attilitag:nl.mathworks.com,2005:Question/4458402019-02-19T15:46:15Z2019-02-19T16:41:13ZSolving simultaneous time-dependent matrix equations I am attempting to solve a set of time-dependent equations which involve matrices. I have tried to use both ode45 and ode15 which both work for equations with one-dimensional variables; as follows:
% Defining constants
A_a = 7.7790;
g1_1 = 0.0019;
g2_1 = 0.0021;
ga_1 = 0.1862;
Hv1 = 2.375;
Hv2 = 2.375;
H1 = 3.9;
CE = 0.82;
Astar1 = 0.9282;
Astar2 = 1.1602;
tspan = [0 9];
Q0 = zeros(3,1);
[t,Q] = ode45(@(t,Q) fun4(t,Q,A_a,g1_1,g2_1,Hv1,Hv2,ga_1,H1,CE,Astar1,Astar2), tspan, Q0)
plot(t,Q(:,1),'-o',t,Q(:,2), '.-')
function dQdt = fun4(t,Q,A_a,g1_1,g2_1,Hv1,Hv2,ga_1,H1,CE,Astar1,Astar2)
dQdt = zeros(3,1);
dQdt(1) = (Astar1^2)*((g1_1*Hv1 + ga_1*(H1 + CE))-((Q(3)^2)/A_a^2));
dQdt(2) = (Astar2^2)*((g2_1*Hv2 + ga_1*(CE))-((Q(3)^2)/A_a^2));
dQdt(3) = Q(1) + Q(2);
end
This solves the equation as expected. However when the constants g1_1, g2_1, and ga_1 each become a 1-by-2 matrix, I tried using a similar function (given below), however, it will not solve the code. Is there a way to use matrices in differential equations?
% Defining constants
A_a = 7.7790;
g1_1 = [0.0019 0.0076]
g2_1 = [0.0021 0.0083]
ga_1 = [0.1862 0.3725]
Hv1 = 2.375;
Hv2 = 2.375;
H1 = 3.9;
CE = 0.82;
Astar1 = 0.9282;
Astar2 = 1.1602;
tspan = [0 9];
Q0 = zeros(3,2);
[t,Q] = ode45(@(t,Q) fun4(t,Q,A_a,g1_1,g2_1,Hv1,Hv2,ga_1,H1,CE,Astar1,Astar2), tspan, Q0)%, options)
plot(t,Q(:,1),'-o',t,Q(:,2), '.-')
function dQdt = fun4(t,Q,A_a,g1_1,g2_1,Hv1,Hv2,ga_1,H1,CE,Astar1,Astar2)
dQdt = zeros(3,2);
dQdt(1) = (Astar1^2)*((g1_1*Hv1 + ga_1*(H1 + CE))-((Q(3)^2)/A_a^2));
dQdt(2) = (Astar2^2)*((g2_1*Hv2 + ga_1*(CE))-((Q(3)^2)/A_a^2));
dQdt(3) = Q(1) + Q(2);
endJShttps://nl.mathworks.com/matlabcentral/profile/authors/14043629-jstag:nl.mathworks.com,2005:Question/4458522019-02-19T16:38:49Z2019-02-19T16:39:35ZIs there a way to predict the run time of mldivide?I am using mldivide to solve systems of linear equations (finding x in Ax = b). Is there a way to predict the run time or output the percentage of progress when using mldivide?
A is a square symmetric positive definite sparse matrix and the matrix size currently approaches 200,000^2 but I would like to increase the size in the future. I want to submit these jobs to a supercomputer but I need to be able to predict the run time and track the progress.
Thanks,
MCHMCHhttps://nl.mathworks.com/matlabcentral/profile/authors/9032009-mchtag:nl.mathworks.com,2005:Question/4458472019-02-19T16:24:08Z2019-02-19T16:37:54ZHow can I use a checkbox value to determine whether to clear other elements in App Designer?I am trying to make the app clear values from edit fields if their corresponding checkbox is unchecked.
When I try to run the code below, I don't get any errors, but nothing happens either.
p = checkbox
ef = text edit field
r,b,f = numeric edit fields
function ClearButtonPushed(app, event)
p=[app.p1.Value,app.p2.Value,app.p3.Value,app.p4.Value,app.p5.Value,app.p6.Value,...
app.p7.Value,app.p8.Value,app.p9.Value,app.p10.Value,app.p11.Value,app.p12.Value];
ef=[app.ef1.Value,app.ef2.Value,app.ef3.Value,app.ef4.Value,app.ef5.Value,app.ef6.Value,...
app.ef7.Value,app.ef8.Value,app.ef9.Value,app.ef10.Value,app.ef11.Value,app.ef12.Value];
r=[app.r1.Value,app.r2.Value,app.r3.Value,app.r4.Value,app.r5.Value,app.r6.Value,...
app.r7.Value,app.r8.Value,app.r9.Value,app.p10.Value,app.p11.Value,app.p12.Value];
b=[app.b1.Value,app.b2.Value,app.b3.Value,app.b4.Value,app.b5.Value,app.b6.Value,...
app.b7.Value,app.b8.Value,app.b9.Value,app.b10.Value,app.b11.Value,app.b12.Value];
f=[app.f1.Value,app.f2.Value,app.f3.Value,app.f4.Value,app.f5.Value,app.f6.Value,...
app.f7.Value,app.f8.Value,app.f9.Value,app.f10.Value,app.f11.Value,app.f12.Value];
for n=1:12
if(p(n) == 0)
ef(n) = ' ';
r(n) = 0;
b(n) = 0;
f(n) = 0;
end
end
end
Jacob Amenthttps://nl.mathworks.com/matlabcentral/profile/authors/10296468-jacob-amenttag:nl.mathworks.com,2005:Question/4458222019-02-19T14:35:43Z2019-02-19T16:36:56ZData Analysis advance filteringI have table which has 200 variables. 4 different types. A1,A2...A50,B1,B2...B50,C1,C2....C50,D1,D2.....D50. "THESE ARE THE COLUMN NAMES." I want to apply multiple filters to multiple columns.
Like
(( B1,B2... 50 > 3) & (A1, A2....A50 > 0.1) & (C1,C2....C50 < 1))
And I want to remove each row which does not fit the criteria from the table.
Please help.Devansh Patelhttps://nl.mathworks.com/matlabcentral/profile/authors/10772536-devansh-pateltag:nl.mathworks.com,2005:Question/4458502019-02-19T16:36:09Z2019-02-19T16:36:09ZHow do I detect pupil size using eye image ?I want to detect eye pupil size of given image how can i do that in matlab . Mehreen Mianahttps://nl.mathworks.com/matlabcentral/profile/authors/10334540-mehreen-mianatag:nl.mathworks.com,2005:Question/4457852019-02-19T10:32:57Z2019-02-19T16:30:46ZLooping the data along with deliminaters (please find the code below)I have to read data from the serial port multiple times like
A = fscanf(t)
B = fscanf(t)
C = fscanf(t)
D = fscanf(t)
E = fscanf(t) and so on i had to do it manually. so i tried the code below for making it simple, and also i have deliminaters for example M and L
n = 10000;
% while loop execution
while( n < 10000 )
A= fscanf(t);
end
but it is not working could any one please help me with the sameRakesh Yadav Kodarihttps://nl.mathworks.com/matlabcentral/profile/authors/10084164-rakesh-yadav-kodaritag:nl.mathworks.com,2005:Question/4450332019-02-14T19:18:58Z2019-02-19T16:29:42ZSolve nonlinear equation with different parameters Hello,
I would like to solve a (quite complicated) equation that looks like this:
pi/2*C*x + 0.5*(3 - gamma^2 - 2*gamma)*C*V^2 + 2*A*V + 2*x*B^2 - pi/2*F;
where gamma is also a function of x and it's defined as following:
gamma = gamma0*exp(-D*atan((B*x)./(C*Vdc)))*sqrt(1+((B*x)/(C*V)));
So, in the end, it can be considered as one (long) equation.
The unkowns are x and Vdc. I was thinking of defining the value of Vdc as a linsopace vector, for example, and see the value of x for each variation of Vdc (by making a loop). The question is: how can I solve the equation?
Also, would it be possible to solve the same equation by making varying other parameters of it (by making a loop on them)?
Thank you in advance for your help! letoppinahttps://nl.mathworks.com/matlabcentral/profile/authors/8974289-letoppinatag:nl.mathworks.com,2005:Question/4456142019-02-18T16:35:35Z2019-02-19T16:29:33ZHow do I extract a function calculated and used inside my ode45 function?Hello,
I'm using ode45 to produce solutions to ODE's and It works. However, I have a function inside of the code that I want to do a graph in the main.m. The system is modelled with the following equations:
Well, the graph I want to do is and versus time. Do you have any ideas how to get them?
Thank you very much in advance
Ignacio Lópezhttps://nl.mathworks.com/matlabcentral/profile/authors/14814368-ignacio-lopeztag:nl.mathworks.com,2005:Question/4458492019-02-19T16:29:31Z2019-02-19T16:29:31ZMATLAB generate .net eventHello,
I want to use the Library Compiler to generate a .NET assembly from some MATLAB code I created.
Is it possible to also generate a .NET event from the generated assembly? Compiling the code towards a .NET assembly works fine but I don't know how to generate an event from within the code.
The reason I want to have this functionality is because the processing in MATLAB takes a very long time and I want to signal the calling application about the progress of the execution (percentage completed).
I tried to look for an example but couldn't find it. Thanks for the help!dennis vanotterdijkhttps://nl.mathworks.com/matlabcentral/profile/authors/12274788-dennis-vanotterdijktag:nl.mathworks.com,2005:Question/4458452019-02-19T16:23:25Z2019-02-19T16:29:27Zerror: too many output argumentsHi! I'm new to MATLAB, so I'd appreciate it if someone could help me. Here is my code for the position analysis of a slider-crank mechanism. Whenever I try to run the code, the command window says: "Error using UnitVector: Too many output arguments. Error in SliderCrank2 (line 29): [e1,n1] = UnitVector(0);"
% SliderCrank_Position_Analysis.m
% performs a position analysis on the slider-crank linkage and
% plots the piston position as a function of crank angle
% by Karolina Kolodziej, February 20, 2019
clear, clc;
a = 0.10; % crank length (m)
b = 0.26; % connecting rod length (m)
c = 0.0; % vertical slider offset
% Ground pins
x0 = [0;0]; % ground pin at A (origin)
% solving for conn. rod angle (theta 3) and piston pos. (d)
N = 361; % # of times to perform calc.
[xB,xC] = deal(zeros(2,N)); % allocate space for pins B and C
[theta2, theta3, d] = deal(zeros(1,N)); %".." for link angles
% Main loop
for i = 1:N
theta2(i) = (i-1)*(2*pi)/(N-1);
theta3(i) = asin((c-a*sin(theta2(i)))/b);
d(i) = a*cos(theta2(i)) + b*cos(theta3(i));
% calculate unit vectors
[e1,n1] = UnitVector(0);
[e2,n2] = UnitVector(theta2(i));
[e3,n3] = UnitVector(theta3(i));
% solve for position of point B
xB(:,i) = FindPos(x0,a,e2);
xC(:,i) = FindPos(xB(:,i),b,e3);
end
plot(theta2*180/pi,d*100,'o','Color',[153/255 153/255 153/255])
hold on
plot(theta2*180/pi,xC(1,:)*100,'Color',[0 110/255 199/255])
title('Piston Position versus Crank Angle for Slider-Crank')
xlabel('Crank angle (degrees)')
ylabel('Position (cm)')
legend('d','xC')
grid on
Karolina Kolodziejhttps://nl.mathworks.com/matlabcentral/profile/authors/14696176-karolina-kolodziejtag:nl.mathworks.com,2005:Question/4458482019-02-19T16:27:22Z2019-02-19T16:28:53ZHow to create a fitnet neural network with multiple hidden layers?I am new to using the machine learning toolboxes of MATLAB (but loving it so far!)
From a large data set I want to fit a neural network, to approximate the underlying unknown function. I have used the "Neural Net Fitting" app and generated a script with it which builds and trains my network. It all works, however the results are not good enough. I think the network is not complex enough to cover the non-linearities. So, I figued I'd add another hidden layer, but I can't get it to work.
The current code to produce the network is the following (which is the default):
trainFcn = 'trainlm'; % Levenberg-Marquardt backpropagation.
% Create a Fitting Network
hiddenLayerSize = 10;
net = fitnet(hiddenLayerSize, trainFcn);
How would I modify this to add more hidden layers?
I am looking to get the classical Multi-Layer Perceptron (MLP) network, with potentially even more hidden layers:
Robert Rooshttps://nl.mathworks.com/matlabcentral/profile/authors/5696016-robert-roostag:nl.mathworks.com,2005:Question/4458382019-02-19T15:35:48Z2019-02-19T16:26:52ZRemoving elements of array by condition and without resizing?I'm trying to produce an array to later write into a .txt file. Currently, the array I am working with is a 5323x18 double. Due to the nature of its conception, roughly all the first 3-5 columns contain a non-zero numerical value, while the other columns (6-18) occasionally contains a non-zero numerical value. The rest of the elements of the array are zero. In order to ensure that the .txt file doesn't have any of these zeros, is there any way I can delete those elements from the array, while maintaining the array size?
For example, turning something like the following array:
[ 1 5 0 0 0 0
1 5 6 7 0 0
4 0 0 0 0 0
5 5 5 5 5 5]
to
[ 1 5
1 5 6 7
4
5 5 5 5 5 5]
Jonathan Cardozahttps://nl.mathworks.com/matlabcentral/profile/authors/14825789-jonathan-cardozatag:nl.mathworks.com,2005:Question/4458052019-02-19T12:41:54Z2019-02-19T16:24:54ZSplitting a matrix based on certain values in the rowsI have a matrix A like this:
A = [911 911;
0 2;
8 5;
7 3;
911 911;
5 3;
1 6;
6 7;
911 911;
3 5;
8 4];
I want to split the matrix A into three matrices (A1,A2,A3) based on the row values 911 like this:
A1 = [0 2; 8 5; 7 3];
A2 = [5 3; 1 6; 6 7];
A3 = [3 5; 8 4];
I need to do this thing inside a for loop which will give the spitted matrix one after another. Attahttps://nl.mathworks.com/matlabcentral/profile/authors/9232138-attatag:nl.mathworks.com,2005:Question/4458462019-02-19T16:23:31Z2019-02-19T16:23:31ZCell contents reference from a non-cell array object from a txt fileHi, can you help me I am trying to run a function however gets stuck when I want it to open & read from my txt files where the 1st column is Iaa, 2nd errAA and so on ...
function [results] = kZ(Iaa,errAA,Ibb,errBB,time)
for k = 1:4
textFileName = ['A' num2str(k) '.txt'];
if exist(textFileName, 'file')
fid = fopen(textFileName, 'rt');
mydata = fread(fid);
fclose(fid);
else
fprintf('File %s does not exist.\n', textFileName);
end
end
Iaa = mydata{k}(:,1);
errAA = mydata{k}(:,2);
Ibb = mydata{k}(:,3);
errBB = mydata{k}(:,4);
time = mydata{k}(:,5);
ABsub = Iab - Iab(1);
BAsub = Iba - Iba(1);
[AAcol,AArow] = size(normAA);
if AArow > AAcol
normAA = normAA';
end
[BBcol,BBrow] = size(normBB);
if BBrow > BBcol
normBB = normBB';
end
[ABcol,ABrow] = size(normAB);
if ABrow > ABcol
normAB = normAB';
end
[BAcol,BArow] = size(normBA);
if BArow > BAcol
normBA = normBA';
endAngelo Figueiredohttps://nl.mathworks.com/matlabcentral/profile/authors/7365651-angelo-figueiredotag:nl.mathworks.com,2005:Question/4458042019-02-19T12:14:53Z2019-02-19T16:19:07Zi need a rough k means code anyone help me plzz ...the following code has some errors.function [rkm] = Km(I,K,wlower,threshold)
I = imread('1.jpg');
I = im2double(I); % Load Image
F = reshape(I,size(I,1)*size(I,2),3);
wupper=1-wlower;
K = 8;
F_ORG=F;
N=fix(size(F,1)/k);
for i=1:k
lowap(:,:,i) = F( ceil(rand(N,1)*size(F,1)) ,:);
F(ismember(F,lowap(:,:,i),'rows'),:)=[]
end
lowap(:,:,i)=(lowap(:,:,i);F);
for i=1:k
upap(:,:,i)=lowap(:,:,i);
end
DAL = zeros(size(F_ORG,1),K+2); % Distances and Labels
KMI = 10; % K-means Iteration
for n = 1:KMI
for i = 1:size(F,1)
upap(:,:,i)(ismember(upap(:,:,i),lowap(:,:,i),'rows'),:)=[];
if (~isempty(lowap(:,:,i)))&& (isempty(upap(:,:,i)))
cents(k,size(F,1))=sum(lowapp(:,:,i),1)/size(lowap(:,:,i));
elseif (isempty(lowap(:,:,i))) && (~isempty(upap(:,:,i)))
cents(k,size(F,1)=sum(upap(:,:,i)/size(upap(:,:,i);
else
cents(k,size(F,1)=wlower*(sum(lowap(:,:,i))/size(lowap(:,:i)))+wupper*(sum(upap(:,:,i))/size(upap(:,:,i)));
for j = 1:K
DAL(i,j) = norm(F(i,:) - cents(j,:));
end
[Distance CN] = min(DAL(i,1:K)); % 1:K are Distance from Cluster Centers 1:K
DAL(i,K+1) = CN; % K+1 is Cluster Label
DAL(i,K+2) = Distance; % K+2 is Minimum Distance
for a=1:k
for b=1:k
if DAL(:,a)/DAL(:,b)<=threshold
end
X = zeros(size(F_ORG));
for i = 1:K
idx = find(DAL(:,K+1) == i);
X(idx,:) = repmat(CENTS(i,:),size(idx,1),1);
end
rkm = reshape(X,size(I,1),size(I,2),3);
end
saradindu ranahttps://nl.mathworks.com/matlabcentral/profile/authors/14824250-saradindu-ranatag:nl.mathworks.com,2005:Question/4455312019-02-18T09:08:02Z2019-02-19T16:16:24Zhelp with ode solvers non-linear ode 1st law of thermodynamicsHello all:
I am trying to solve the ODE's:
d2y/dt2=-g+(P-Pa)*Ap
dP/dt=k*P*((1/m) *(dm/dt) - (k/(L+y))*(dy/dt))
dm/dt=(m/V) [q-c*Ao*(Pa/P)^(1/k) * {2*k/(k-1) * P*V/m *(1-(Pa/P)^((k-1)/k))}^0.5
V(y)=Ap*(L+y)
where w,Ao,q,Ap,Pa,k,L,g are all constants. but P(t),m(t), y(t) are functions of t
I wrote the following M-file but it looks like it's not working for the m variable. Is there anyting wrong with code or state space variable?
##############################################
clear;close all
global Pa;global A;global Wp;global q;global Ao,global c;global L;global k;
Pa=101000;
d=.05;
Wp=7;
q=2;
Ao=0.01;
c=.1;
L=0.75;
k=1.4;
Te=300;
A=0.25*pi*d^2;
mass=(Pa*L*A)/(287*Te);
tic
W=200;
tf=10;
Fs = .1; %sampling rate
Ts = 1/Fs; %sampling time interval
tspan =0:Fs:tf; %sampling period
y0=[0,.0,101000,mass];
[t,y]=ode45(@Sample01,tspan,y0,[]);
%y[YfreqDomain_d,frequencyRange_d]=positiveFFT(y(:,1),Fs);
subplot(2,2,1);plot(t,y(:,1),'k');
subplot(2,2,2);plot(t,y(:,2),'k');
subplot(2,2,3);plot(t,y(:,3)/Pa,'k');
subplot(2,2,4);plot(t,y(:,4),'k');
dlmwrite('tssst',[y]);
toc
HERE IS THE FUNCTION OF STATE SPACE
function y_dot=Sample01(t,y)
global Pa;global A;global Wp;global q;global Ao,global c;global L;global k;
y_dot=zeros(4,1);
y_dot(1)=y(2);
y_dot(2)=-Wp*9.81/Wp+(y(3)-Pa)*A/Wp;
y_dot(3)=y(3)*((k/y(4))*y_dot(4)-(k/(L+y(1)))*y(2));
y_dot(4)=y(4)/(L+y(1))*(q-c*Ao*(Pa/y(3))^(1/k)*((2*k/(k-1))*y(3)*(L+y(1))/y(4)*(1-(Pa/y(3))^((k-1)/k)))^0.5);
Ahmed S. Sowayanhttps://nl.mathworks.com/matlabcentral/profile/authors/8027473-ahmed-s-sowayantag:nl.mathworks.com,2005:Question/4458122019-02-19T13:21:29Z2019-02-19T16:11:08ZConstant heat flux boundary conditionhow to give constant heat flux boundary condition? i am solving a phase change problem by coding in MATLABsumukha hegdehttps://nl.mathworks.com/matlabcentral/profile/authors/12245974-sumukha-hegdetag:nl.mathworks.com,2005:Question/4458262019-02-19T14:45:23Z2019-02-19T16:10:26Zcontour plot real numbersI wrote a program that just takes an input of x and y values and calculates the principal stresses. It keeps giving me an error about input arguments for contour must be real. All the variables are squared so I am not sure how I would be getting this problem. Thanks.
clc
clear all
% Load
P = 1;
% Length of Beam
L = 1;
% Height of Beam from Neutral Axis
c = 0.1;
x = linspace(0,L);
y = linspace(-c,c);
[X,Y] = meshgrid(x,y);
sigmaP1 = ((3*P/(4*(c^3)))*[X*Y+[((c^2-Y^2)^2)+(X^2)*(Y^2)]^(1/2)]);
contourf(X,Y,sigmaP1,'ShowText','on')Derek Reitnouerhttps://nl.mathworks.com/matlabcentral/profile/authors/3412572-derek-reitnouertag:nl.mathworks.com,2005:Question/4427012019-02-01T16:32:08Z2019-02-19T16:10:22ZDoes function linprog by interior point method have crossover process to obtain a basic solution? Greetings,
Currently, I am working on a linear programming problem. I used function linprog to solve it. However, I found if I specified either using interior point method or dual simplex method, I would get totally different solutions. The reason is the existence of multiple optimal solutions.
As we know, dual simplex method gives a vertex solution. How about interior point method? If interior point method has crossover process, I should get a vertex solution (basic solution). If it has not, I will get a inner point of the hyperplane of constraints.
Does function linprog by interior point method have crossover process to obtain a basic solution? Devinhttps://nl.mathworks.com/matlabcentral/profile/authors/9056045-devintag:nl.mathworks.com,2005:Question/4190362018-09-13T04:00:00Z2019-02-19T16:10:20ZWhat happened to the figure toolbar in R2018b? Why is it an axes toolbar? How can I put the buttons back?In R2018b, tools such as the zoom, pan, datatip, etc are no longer at the toolbar at the top of the figure window. These buttons are now in an "axes" toolbar and only appear when you hover your mouse over the plot. How do I put the buttons back at the top of the figure window?
<<http://www.mathworks.com/matlabcentral/answers/uploaded_files/142593/b53c2d62f5bb995fe63fe61cf81eaf86.png>>
MathWorks Support Teamhttps://nl.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:nl.mathworks.com,2005:Question/4458442019-02-19T16:08:30Z2019-02-19T16:08:30ZAverage of two colliding meshedHello,
How can I find average of two meshes that are colliding with each other at a certain point?
Harsh Makwanahttps://nl.mathworks.com/matlabcentral/profile/authors/14713231-harsh-makwanatag:nl.mathworks.com,2005:Question/4458432019-02-19T16:08:24Z2019-02-19T16:08:24ZPulse and Glide Looping ProblemI have this script which is being used for a project, the for and while loops run succesfully, however i wish to be able to carry the final velocity and displacement values from one for loop into the beginning of the next for continuity as it currently resets to zero at the beginning of each loop. Is there anyone who might be able to help me please. some parts are commented out so the script runs quickly to work out the bugs.
%Driving Parameters
clear vars;
close all;
Incremental_Distance=2090;%distance per section of the designated route [m]
v_max=16; %Maximum pulse speed [m/s]
v_min=7; %Minimum coast speed [m/s]
%
%resistance
Cd=0.09; %Coefficient of aero drag
RRt=0.0014; %Tyre rolling resistance
RRh=0.0014; %Hub rolling resistance
Af=0.9; %Frontal area of the vehicle [m^2]
%
%Pressure and Temp
P_Air=101325; %Air Pressure [Pa]
T_AirC=25; %Air temperature [Degree Celcius]
T_AirK=T_AirC+273.15; %Air temperature [Kelvin]
%
%Driving forces
Torque=450; %Engine torque(rated constant) [Nm]
Gr=1; %Effective gear reduction
Eft=0.9; %Transmission Efficiency
RPM=2500; %Engine RPM (rated constant) [rpm]
RPMrad=RPM/(60*2*pi); %RPM in [rad/s]
r=0.2; %Diameter of driving wheel [m]
% theta=xlsread('newLEJOG_Route.xlsx','H1:H649'); %road incline
theta = [0.0378;0.0072;0.0092];
%
%Physical Constants
g=9.812; %Acceleration due to gravity[m/s^2]
R=286.9; %Gas constant [J/Kg*k]
rho=(P_Air/(R*T_AirK)); %Density of air based on pressure and temperature [Kg/m^3]
Mc=200; %Mass of Car [Kg]
Md=65; %Mass of Driver [Kg]
Mt=Mc+Md; %Total mass of vehicle [Kg]
%
%Fuel Consumption
Mass_flow=2.164211E-05; % fuel flow rate from injector [Kg/s]
Fuel_Density=0.755; %density of fuel [Kg/l]
Pulse_width=5E-04; % [s]
%
%Coefficient Calculations
RR=((RRt*4)*(Mt/4)*g)+(4*RRh*Mt*g); %total rolling resistance of wheel assembly [N]
%
%initial conditions
x=zeros(length(theta)),1; %initial dispacement [m]
v=zeros(length(theta)),1; %initial Velocity [m/s]
Pulse_mark=1; %initial pulse mark
%
%incremental values
dt=0.1; %time step
Ft=(Torque*Gr*Eft)/r;
%
%Mathematical model0
for i=1:length(theta) %road incline [rads]
Grade(i)=Mt*g*sin(theta(i));
k=1; %solution step
while x(i,k)<=Incremental_Distance
Daero(i,k) = 0.5*rho*Cd*Af*v(k)^2;
if Pulse_mark==1
a(i,k)=((Ft-RR-Grade(i)-Daero(i,k))/Mt);
else
a(i,k)=((-RR-Grade(i)-Daero(i,k))/Mt);
end
v(i,k+1) = v(i,k) + a(i,k)*dt;
if v(i,k+1) >= v_max
Pulse_mark = 0;
v(i,k+1) = v_max;
elseif v(i,k+1) <= v_min
Pulse_mark = 1;
end
x(i,k+1) = x(i,k)+v(i,k+1)*dt;
k=k+1;
end
if i < length(theta)
v(i+1,1) = v(i,end);
x(i+1,1) = x(i,end);
k_steps(i+1,1) = k_steps(i,end);
end
%
% time(i) = k_steps(i,k)*dt;
%
end
xx=transpose(x);
vv=transpose(v);
v_column = [];
for ii=1:size(vv,2)
v_column = [v_column; vv(:,ii)];
end
x_column = [];
for ii=1:size(xx,2)
x_column = [x_column; xx(:,ii)];
end
%Fuel Consumption calculations
Total_time=time; %[s]
Total_Dispacement=x(i,k); %[m]
Final_Velocity=v(i,k); %[m/s]
% Average_Velocity=mean(v); %[m/s]
% Fuel_Consumed=((Pulse_width*Mass_flow*RPMrad*Pulse_Time)/(fuel_Density*2*60*60))/100; %[Litres]
% Mileage_per_L=Total_Distance/Fuel_Consumed; %[m/L]
% Mileage=Mileage_per_L/1000; %[Km/l]
%Plots
% figure(4); plot(x_column(:),v_column(:),'.-'); title('pulse and glide'); xlabel('meters'); ylabel('m/s'); grid minor;
% figure(1); plot(k_steps,x_column); title('position'); xlabel('seconds'); ylabel('meters'); grid minor;
% figure(2); plot(k_steps,v_column); title('velocity'); xlabel('seconds'); ylabel('m/s'); grid minor;
figure(3); plot(x_column,v_column); title('pulse and glide'); xlabel('meters'); ylabel('m/s'); grid minor;
Alex Deeganhttps://nl.mathworks.com/matlabcentral/profile/authors/11473516-alex-deegantag:nl.mathworks.com,2005:Question/4452462019-02-16T00:52:49Z2019-02-19T16:06:19ZConditionally Defining a Variable using ODE45How could I take this code I'm using and conditionally define my variable 'p'? For example, I want p=0 everywhere except when 3<t<4, then I want p=1.2. Here is my code:
tspan=[1 7];A0=1;P0=1;g=1;p=0;B=0.15;
[t,x] = ode45(@(t,x) [-g*x(1) + p*x(1); -x(1)*x(2)+ B*x(2)], tspan, [A0 P0]);Thomas Veithhttps://nl.mathworks.com/matlabcentral/profile/authors/13550529-thomas-veithtag:nl.mathworks.com,2005:Question/4456012019-02-18T15:53:19Z2019-02-19T16:04:23ZCan anyone point out the mistake in this program? It's regarding writing a function to check if the entered date is valid or not.Here is the code that I have written, but it gives wrong answers for date such as 31st April 2018 (2018,4,31). Ideally the program should give me logical 0, however, it gives me logic 1.
function [valid]=valid_date(year, month, day)
if isscalar(year) && year>0 && year~=0 && isscalar(month) && month>0 && month~=0 && isscalar(day) && day>0 && ar
if mod(year,4) == 0 && mod(year, 100)~= 0 || mod(year,400)==0 && month==2 && days<=29
%for february
valid=true;
else
valid=false;
end
%for rest of the months
if month==4 || month==6 || month==9 || month==11 && day<=30
valid=true;
elseif month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month== 12 && day<=31
valid=true;
else
valid=false;
end
%not a leap year
if month==2 && day>28
valid=false;
end
%rest of the months
if month==4 || month==6 || month==9 || month==11 && day<=30
valid=true;
elseif month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month== 12 && day<=31
valid=true;
else
valid=false;
end
else
valid=false;
end Sanjeeb Bharalihttps://nl.mathworks.com/matlabcentral/profile/authors/14790037-sanjeeb-bharalitag:nl.mathworks.com,2005:Question/4422102019-01-30T06:50:19Z2019-02-19T16:02:29ZCNN Training progress plots - Validation accuracy Jumps at last iterationDear collegues,
I'm training a CNN on MATLAB and I noticed what you can see in the figure below. As shown in the training progress plots, the validation accruacy jumps at the very last iteration regardless of what's the number of Epoches used in the traning. It is confusing. What could be the reason for that?
Thank you.
#Epoches = 5
#Epoches = 10
Another trail with #Epoches = 10
Mariam Ahmedhttps://nl.mathworks.com/matlabcentral/profile/authors/13281799-mariam-ahmedtag:nl.mathworks.com,2005:Question/4458422019-02-19T16:01:50Z2019-02-19T16:01:50Zpolarity signal transmitter separated ?I want to separate the negative signal from the positive signal?
x=41 ; %number of pn
pn= [10 -5 4 - 8 10 8 9 6 -7 - 9 7 - 6 5 6 -4 2 -3 -4 5 -7 -6 -8 9 4 11 -8 -5 6 -4 -7 -8 9 7 6 3 2 4 5 6 8 7 9 -5 -9 8 -5 7 ];
xp=pn(pn>0); % positive signal
xn=pn(pn<0); % negative signal
Xn=abs(Xn); % absolute
I want to set a break between positive and negative signals by (x /4).
i:e
d=(x/4);
xv= xn+d % d is the delay
I also want to trace the length of both positive and negative signals to be able to decode the code again.
tx=[xp,xv] %transmit signal
abdullah qasimhttps://nl.mathworks.com/matlabcentral/profile/authors/12485153-abdullah-qasimtag:nl.mathworks.com,2005:Question/4458342019-02-19T15:18:04Z2019-02-19T15:58:19Zhow to generate permutations of N numbers in K positionsI want to generate all permutations of N numbers in K places, where K is less than N (nPk) in matlab, I've searched online and already existing questions but couldn't find a functions which generates such permutations without repitition. There are some functions which do this with repitation.
For example if I've a vector [1 2 3 4] my N is 4 and my K is 2, then I want 12 permutations using the formula N!/(N-K)1 = 4!/(4-2)! = 12
[1,2]
[1,3]
[1,4]
[2,1]
[2,3]
[2,4]
[3,1]
[3,2]
[3,3]
[4,1]
[4,2]
[4,3]
These are the permutations which I want to generate. Kindly suggest me the solution.Ali Danishhttps://nl.mathworks.com/matlabcentral/profile/authors/14825603-ali-danishtag:nl.mathworks.com,2005:Question/4458412019-02-19T15:52:15Z2019-02-19T15:52:15ZNN Predictive Controller for MIMO SystemI'm trying to control a system in Simulink using the NN Predictive Controller from the Deep Learning Toolbox.
It seems to work fine for SISO systems, but my system has five inputs (including the control signal) and four outputs. Plant identification and training both complete with no errors, but when I run the simulation I get the following errors:
Error in port widths or dimensions. Output port 1 of 'controller/NN Predictive Controller/NN model/Unit Delay1' has 4 elements. This port does not accept the dimensions (or orientation) specified by the output signal.
Error in port widths or dimensions. Output port 1 of 'controller/NN Predictive Controller/NN model/Unit Delay1' has 4 elements. This port does not accept the dimensions (or orientation) specified by the output signal.
All of my dimensions are consistent (the reference and plant output are both 4x1). Both of the errors seem to be referring to the Simulink block itself.
Similar questions have been asked on this website and others but none have answers, so I'm hoping that someone will be able to help.Arie Schwartzhttps://nl.mathworks.com/matlabcentral/profile/authors/10070077-arie-schwartztag:nl.mathworks.com,2005:Question/4456172019-02-18T17:12:38Z2019-02-19T15:51:17ZHow to load set of images into workspace for training?I'm working on currency recognition. How can i apply set of images of currency notes into workspace in matlab to use for training? Hiruni Gunawardhanehttps://nl.mathworks.com/matlabcentral/profile/authors/14363488-hiruni-gunawardhanetag:nl.mathworks.com,2005:Question/4458392019-02-19T15:43:09Z2019-02-19T15:51:06ZAbout helperVideoPlayerSet.m function in Automated Driving System ToolboxHi, I'm currently using the Automated Driving System Toolbox in MATLAB 2018b. As I was trying the demos provided in the official documentation(wedsite here:https://ww2.mathworks.cn/content/dam/mathworks/tag-team/Objects/v/80866v00_Visual_Perception_Using_Monocular_Camera.pdf), I found that the first few step worked out correctly, however, in the 'Simulate a Complete Sensor with Video Input' section, the software reported 'Undefined function or variable 'helperVideoPlayerSet '. '. This function, according to the documentation, was called withnin a supporting function named 'visualizeSensorResults', which was offered at the end of the documentation. I am really confused right now.
Many thanks to those who happen to read this question and give me advice.Lucashttps://nl.mathworks.com/matlabcentral/profile/authors/14152670-lucastag:nl.mathworks.com,2005:Question/4458202019-02-19T14:20:17Z2019-02-19T15:47:56Zproblems to add yticklabel in log-log figureDear all,
I have some issue to illustrate a ytick label in a figure. Here is the piece of code related to this:
The ytick label 10^{0} does not appear in this case! Any ideas?
CheersPatrick Lauxhttps://nl.mathworks.com/matlabcentral/profile/authors/2725543-patrick-lauxtag:nl.mathworks.com,2005:Question/4453682019-02-17T04:35:06Z2019-02-19T15:47:52ZHow to split data in reference to certain values from one column and organise into a cell array?- The logical indices in position 1 contain a true value outside of the array bounds. ERRORI have a large data selection of 1037803 points for each test and 3 repeats. The data has 12 columns that indicate various different parameters. Column 6 indicates the speed of which the test ran. In total there was 100 different speeds. The first speed is 31.4159261390256 and then it increases by 31.4159 each time up to the last speed of 3141.59. Therefore, i want to split the data into a cell array that includes 100 rows, one for each speed with the data for each test next to it.
I have used this;
for n= 0:100 % 100 different speeds
ans = n;
indexes=((New_Data{1,1}(:,6)> (31+31.4159*n)& (New_Data{1,1}(:,6)<(32.4159+31.4159*n))) ) ; %values are not completly fixed and change by some degree
speeds{n+1,1} = num2str(31+31.4159*n); %first column = the speed values
speeds{n+1,2} = New_Data{:,1}(indexes,:); %test 1
speeds{n+1,3} = New_Data{:,2}(indexes,:); %test 2
speeds{n+1,4} = New_Data{:,3}(indexes,:); %test 3
end
This works well untill New Data {:,3} for the last speed, where it appears blank (figire 1) . I have checked my data and the data is same length and has the final speed so the original data is defo not the issue (figure 2).
I keep getting the following error.
The logical indices in position 1 contain a true value outside of the array bounds.
Error in dat_proc2 (line 58)
speeds{n+1,4} = New_Data{:,3}(indexes,:);
But if i just look at data 3 (test 3) alone it seems to work but as soon as i look at it with the other 2 tests i get this error.
I think it may be the indexing. If anyone can help me solve this problem that would be great.
Sufia Fatimahttps://nl.mathworks.com/matlabcentral/profile/authors/12508175-sufia-fatimatag:nl.mathworks.com,2005:Question/4458352019-02-19T15:23:13Z2019-02-19T15:43:01ZBayesian regularization of neural network (Effective # param)I wrote a code to perform Bayesian regularization of neural network using the neural network material by Martin T Hagan.
My code gives similar results with that of matlab for performance, sum squared parameter, but fails to give the same value for Effective number of parameter.
The formular i used for effective number of parameter is n - 2(alpha * trace_of_inverse_of_hessian_matrix) as described in the book.
My question is: what equation or formular does matlab use in estimating the effective number of parameter?uhunomahttps://nl.mathworks.com/matlabcentral/profile/authors/8984792-uhunomatag:nl.mathworks.com,2005:Question/4456722019-02-18T21:35:21Z2019-02-19T15:40:29ZUsing other solvers for models generated by optimproblemHello,
I am wondering if there is a way to use other solvers to solve models (problems) built by new optimization toolbox (i.e. optimproblem, optimvar, optimconstr, etc.)? Because if MATLAB uses it's own solvers and needs to struct A, b, and c matrix and vectors, just an output of these parameters will facilitate using all other well-known solvers too. Vahid Mahmoodianhttps://nl.mathworks.com/matlabcentral/profile/authors/12149466-vahid-mahmoodiantag:nl.mathworks.com,2005:Question/4458182019-02-19T14:12:28Z2019-02-19T15:38:12ZHow to create a multi-index vectors?I have to create some vectors containing the values of a d-degree n-dimensional multi-index. A d-degree n-dimensional multi-index is a n-tuple such that .
Just to give an example, if I want a 2-degree 3-dimensional multi-index, I have to built the vectors:
I can to create them for the 2-dimensional case (basicly, I create a matrix and take the upper-right part), but when I move to higher dimensions I have no clue how to go on.
Do you have some suggestion?CaGhttps://nl.mathworks.com/matlabcentral/profile/authors/11077495-cagtag:nl.mathworks.com,2005:Question/4414542019-01-25T12:03:21Z2019-02-19T15:35:58Zplotting moving data pointsI'm trying to plot a skeleton model using the coordinates of the joints.
I extracted the x,y, and z coordinates and saved them in 3 matrices.
I'm trying to plot the first row of each column then have a small pause and plot the next row of each matrix.
each row of the matrices correspond to the x,y, and z coordinates of the joints and together they make a frame.
mamdouh aljoudhttps://nl.mathworks.com/matlabcentral/profile/authors/12716714-mamdouh-aljoudtag:nl.mathworks.com,2005:Question/4458372019-02-19T15:35:04Z2019-02-19T15:35:04Zhow to cite a reference of matlab 2018 in research paperHow do i cite a reference of matlab 2018 in my researchTanmay Agarwalhttps://nl.mathworks.com/matlabcentral/profile/authors/14520151-tanmay-agarwaltag:nl.mathworks.com,2005:Question/4458362019-02-19T15:33:39Z2019-02-19T15:33:39Zsolve 3 parameter weibull using method of moments - integral with parameters inside a solveHi all,
I am trying to use the method of moment to solve the 3 parameters of the weibull distribution. I have input all the equations however the intergal function embedded gives me an output error. I am not sure how to embed the integral into the solve function. I.e. the integral is complaining that is has a variable and not a value. Here is a link to the euqations for the moments.
"Error using integral (line 85): A and B must be floating-point scalars.
Error in MOM>@(n)integral(@(s)fun(s,n),0,n)
Error in MOM (line 21) : eqn=[c +
(a*(g(1+1/b)))==u,a*sqrt(g(1+2/b)-(g(1+1/b))^2)==var,(g(1+3/b)-3*g(1+1/b)*g(1+2/b)+2*(g(1+1/b))^3)/((g(1+2/b)-(g(1+1/b))^2)^1.5)==skew;]"
note I use 'name' cause i have multiply files which I would need to apply this too.
name=strcat('Location_',num2str(p,'%02d'),'_hs.mat');
load(name);
u=nanmean(values);
var=std(values);
skew=skewness(values);
s=values;
syms a b c
fun=@(s,n) s.^(n-1).*exp(-s); %integal of the gamma function
g=@(n) integral(@(s)fun(s,n),0,n); %gamma funtion
eqn=[c + (a*(g(1+1/b)))==u,a*sqrt(g(1+2/b)-(g(1+1/b))^2)==var,(g(1+3/b)-3*g(1+1/b)*g(1+2/b)+2*(g(1+1/b))^3)/((g(1+2/b)-(g(1+1/b))^2)^1.5)==skew;]
vars=[a b c];
[sola, solb, solc]=solve(eqn, vars)Lauren Arendsehttps://nl.mathworks.com/matlabcentral/profile/authors/11767508-lauren-arendsetag:nl.mathworks.com,2005:Question/3970662018-04-24T14:03:19Z2019-02-19T15:28:39ZHow do i calculate the inverse of a non-square matrix?I have a 4x3 matrix(S) and i want to calculate the inverse of it, the matrix is:
S=
1.7530 0 0 0
0 0.1009 0 0
0 0 0.0149 0
but since it is not a square matrix when i use S^-1 it says i have to use elemental wise power. The problem is when i use elemental-wise power the zeros go to 'Inf' so what do i do?Feliciano Döringhttps://nl.mathworks.com/matlabcentral/profile/authors/10365947-feliciano-doringtag:nl.mathworks.com,2005:Question/4450262019-02-14T18:31:23Z2019-02-19T15:22:47ZHow can I generate an array of binary data of this form?The N is input.
I want to write a code which gives array of dimension (combin X N) where combin is all possible combination such that sum of each row is N/2.
Confusion? Let me explain with an example...
Let N = 4, I want output array of the following form
[0 0 1 1
0 1 0 1
0 1 1 0
1 0 0 1
1 0 1 0
1 1 0 0]
note that the sum of each row if N/2 = 2. Let's see another example...
if N=6, output should be
[0 0 0 1 1 1
0 0 1 0 1 1
0 0 1 1 0 1
0 0 1 1 1 0
0 1 0 0 1 1
0 1 0 1 0 1
..... so on...]
I have a code but it is very inefficient (and also it does not work for N>18 (also it's very slow)
A = dec2bin( 1:2^N-1)-'0';
required_array = A(sum(A,2)==N/2,:);Luqman Saleemhttps://nl.mathworks.com/matlabcentral/profile/authors/9731121-luqman-saleemtag:nl.mathworks.com,2005:Question/1048322013-11-04T13:41:15Z2019-02-19T15:17:28Zindex notation symbolic toolboxexample:
fi = sym('fi',[1 2])
fi =
[ fi1, fi2]
I want this to be:
fi =
[ fi(1), fi(2)]
This in order to use outcome of symbolic manipulation directly in my matlab code.
Dinanthttps://nl.mathworks.com/matlabcentral/profile/authors/1191860-dinant