https://es.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions2021-01-17T07:01:28Ztag:es.mathworks.com,2005:Question/7187802021-01-16T19:35:27Z2021-01-17T07:01:28Zimage segmentation using ANN MATLAB Codehi.. i need your help :( i need to predict the land changes using satellite images.. can you give me example coding for ANN image segmentation using matlab.? . Anis Syakirahhttps://es.mathworks.com/matlabcentral/profile/authors/18767391tag:es.mathworks.com,2005:Question/7188352021-01-16T21:43:31Z2021-01-17T06:51:13Zfinding last column valuesI have 12094*3 matrix and 7*2 matrix. Second matrix is coordinates of a polygon which is bounded. I used inpolygon method to analyse the region. I obtained 237 points inside 12094*3. Now i want to find third values of inside points which are third column of 12094*3. Since inpolygon method is 2 dimensional, i have only information about how many points of 7*2 inside in the 12094*3 matrix. I tried find command but it does not work. Although i have 237 points, there are 15 values in workspace i dont know maybe i did wrong.busra gogenhttps://es.mathworks.com/matlabcentral/profile/authors/19358260tag:es.mathworks.com,2005:Question/7189152021-01-17T01:46:38Z2021-01-17T06:43:20ZHow to put a shape on top of an image?Hello.
I want to join two images: a shape (created by mapshow) and an image (created by imasgesc). Is it possible to overlap one another? I need the shape's contours to remain in the image created by imagesc.
I put an example of the shape and the image.
Does anyone know how I can do this?pink flowerhttps://es.mathworks.com/matlabcentral/profile/authors/18011377tag:es.mathworks.com,2005:Question/7189852021-01-17T05:55:15Z2021-01-17T06:35:47ZHow to save last three values from for loop? I just got stuck to save the last three values of r from the for loop, please help me in this regard.
yl = 1;
rl = [0, yl] ;
speed = 50;
theta = 45;
vl = [speed*cos(theta*pi/180), speed*sin(theta*pi/180)];
r = rl; v = vl;
Cd = 0.35; area = 4.3e-3; grav =9.81; mass = 0.145; rho = 1.2; air_const = -0.5*Cd*rho*area/mass;
tau = 0.1;
maxstep = 1000;
for i=1:maxstep
xplot(i) = r(1) ;
yplot(i) = r(2);
t = (i-1)*tau;
xNoAir(i) = rl(1) + vl(1)*t;
yNoAir(i) = rl(2) + vl(2)*t - 0.5*grav*t^2;
accel = air_const*norm(v) *v;
accel(2) = accel (2)-grav;
r = r + tau*v;
v = v + tau*accel;
if( r(2) < 0 )
xplot(i+1) = r(1);
yplot(i+1) = r(2);
break ;
end
end
Thanks for help.Muhammad Usmanhttps://es.mathworks.com/matlabcentral/profile/authors/1613763tag:es.mathworks.com,2005:Question/7184752021-01-16T10:13:22Z2021-01-17T06:26:24ZDo anyone know how to graph your function in the interval from x=0 to infSo i have a problem to find the equation of motion of rocket and plotting it, but when plotting the graph it keeps plotting the part where x is negative
Here it's my code, can someone help me to only plot the part where x>0
Many thanks in advance
syms t positive rational
disp ('Choose upward direction as positive direction');
disp ('Choose ground as the origin of coordinates');
fprintf ('The Newton''s second law equation for rocket motion: ');
disp ('m*dv/dt = -v0*dm/dt - mg');
k = input('Input the fuel combustion speed dm/dt = ');
m0 = input('The rocket''s mass m0 = ');
y0 = input('The rocket''s initial position y0 = ');
v0 = input('The rocket''s gas propulsion speed v0 = ');
g = 9.81;
v = v0*log(m0/(m0-k*t))-g*t;
a = diff(v,t);
fprintf ('The rocket''s acceleration: a = ');
disp (a);
y = y0 + int(v,0,t);
fprintf ('the equation of rocket motion : y =');
disp (y);
fplot(y);
title('Graph of the motion''s equation');
xlabel('Time t');
ylabel('Position y');
grid on;Phong Dohttps://es.mathworks.com/matlabcentral/profile/authors/20127621tag:es.mathworks.com,2005:Question/7189502021-01-17T03:29:53Z2021-01-17T06:22:49ZI want to remove background in the given image.I want to remove background in the given image and only want these red markers in output image, i have almost 150 images of this type so a program that should that use for all frames.
preeti vermahttps://es.mathworks.com/matlabcentral/profile/authors/20581792tag:es.mathworks.com,2005:Question/7189952021-01-17T06:05:15Z2021-01-17T06:12:04ZNewton's Law of Cooling Euler's method, don't understand how it works in matlabHello!
My professor has only given one example on Euler's method, so I'm really working from scratch here and would like guidance on starting Euler's method for this problem:
I apologize for asking a question with none of my own coding given. A starter or pseudocode for the Euler's would be immensely helpful!
You are working as a crime scene investigator and must predict the temperature of a homicide victim over a 5 hour period . You know that the room where the victim was found was at 10 ∘ C when the body was discovered.
Use Newton's law of cooling and Euler's method to compute the victim's body temperature for the 5 hour period using values of k = 0.12/hr and Δ t = 0.5 h r. Assume that the victim's body temperature at the time of death was 37 ∘ C , and that the room temperature was at a constant value of 10 ∘ C over the 5 hour period.
dT/dt = -k(T-T_a)
Newton's law of cooling says that the temperature of a body changes at a rate proportional to the difference between its temperature and that of the surrounding medium (the ambient temperature)
This is what I have so far:
for i=1:12
T(i+1,2)= T(i,2)+0.5*k*(T(i+1,1)-T_f);
endAnastasia Zistatsishttps://es.mathworks.com/matlabcentral/profile/authors/20783629tag:es.mathworks.com,2005:Question/2883842016-06-08T07:04:51Z2021-01-17T05:14:37ZHow to plot the graph of Greatest Integer Function ?I was trying to plot greatest integer function by using floor command and stem (to show discontinuity) but what i am getting is,please help me out!!!
I used the code
x=linspace(1,10,10)
y=floor(x);
stem(x,y)Vipul Sharmahttps://es.mathworks.com/matlabcentral/profile/authors/8298106tag:es.mathworks.com,2005:Question/7156732021-01-13T10:44:54Z2021-01-17T04:41:16Zusing mle in matlabfor a given dataset i need to calculate parameters value using mle where cdf = a*(1-exp(-b*A)) and pdf = a*b*exp(-b*A),if i use following code
A=[6 10 17 20 29 34 38 41 50 55 ];
[phat,pci] = mle(A,'pdf',@(A,x,y) x*y*exp(-y*A),'start',[1,1])
i get
Error using mlecustom>llf_pdfcdf
(line 440)
The PDF function returned negative
or zero values.
Error in fminsearch (line 330)
x(:) = xe; fxe =
funfcn(x,varargin{:});
Error in mlecustom (line 184)
fminsearch(llf,start,opts,uncensData,censData,uncensFreq,censFreq,fun1Args,fun2Args,checkFunVals,lb,ub);
Error in mle (line 247)
[phat, pci] =
mlecustom(data,varargin{:});
I am not able to understand what is wrong and how to rectify it as i am new to matlab.Please help how sholud i evaluate parameters a and b using mle function in matlab.shalini sharmahttps://es.mathworks.com/matlabcentral/profile/authors/20456342tag:es.mathworks.com,2005:Question/7189752021-01-17T04:39:31Z2021-01-17T04:39:31ZProblem connecting Mutual inductor to Solar PV array outputI am Trying to Simulate flyback converter with Solar array output but unable to make connections to mutual inductor however i can connect it to transformer
Please find the attached image for further reference
Thank you
Shrinivasa Ghttps://es.mathworks.com/matlabcentral/profile/authors/15130016tag:es.mathworks.com,2005:Question/3446952017-06-14T07:31:14Z2021-01-17T04:36:10ZWhat is the difference between the given matrix multiplications: A*B and A.*B (A and B are both matrices)When I gave A*B MATLAB gave the predicted output, but when the "dot" precedes the "*" operator it gives some other output
a=[1 2 3;4 5 6;7 8 9];
x=a(:,2);
a.*x
The Output that I get for this is
ans =
2 4 6
20 25 30
56 64 72
Praneeth Lankahttps://es.mathworks.com/matlabcentral/profile/authors/9084396tag:es.mathworks.com,2005:Question/7189702021-01-17T04:14:38Z2021-01-17T04:23:01ZCounting Specific Number of Consecutive Values in a MatrixI have a matrix composed of ones and zeros.
I need to idenity where there are three 1s in each COLUMN
1 0 0 1 1
1 0 1 1 1
1 1 1 0 1
1 0 1 1 1
1 1 0 1 1
0 1 1 1 1
1 1 1 0 1
I want to have the code identify that there are three consecutive 1s in the first through third column and that there are two sets of consecutive 1s in the fourth column.
I then want to compare this matrix with another matrix and find where they are similar in the exact locations of the three consecutive 1s.
Gabriela Garciahttps://es.mathworks.com/matlabcentral/profile/authors/20621151tag:es.mathworks.com,2005:Question/7187102021-01-16T18:22:01Z2021-01-17T04:15:36ZI did not understand the error which is called 'Error using symengine: Array sizes must match.' What should i do?
x1=0.2232585;
x2=0.2232585;
iteration=0;
while true
iteration=iteration+1;
syms x1s x2s t
func=(x2s-x1s^2)^2+(1-x1s)^2;
dif_x1=diff(func,x1s);
dif_x2=diff(func,x2s);
grad_x1_temp=vpa(subs(dif_x1,x1));
grad_x1=vpa(subs(grad_x1_temp,x2));
grad_x2_temp=vpa(subs(dif_x2,x2));
grad_x2=vpa(subs(grad_x2_temp,x1));
tx1_temp=subs(dif_x1,x1-grad_x1*t);
tx1=subs(tx1_temp,x2s,x2-grad_x2*t);
tx2_temp=subs(dif_x2,x2s,x2-grad_x2*t);
tx2=subs(tx2_temp,x1s,x1-grad_x1*t);
eqn=tx1*grad_x1+tx2*grad_x2;
a=solve(eqn,t,'Real',true);
val_temp=vpa(subs(func,x1s,x1));
val=vpa(subs(val_temp,x2s,x2));
x1=x1-grad_x1*a;
x2=x2-grad_x2*a;
val_temp_end=vpa(subs(func,x1s,x1));
val_end=vpa(subs(val_temp_end,x2s,x2));
if(val_end>val)
break;
end
end
iteration
Error using symengine
Array sizes must match.
Error in sym/privBinaryOp (line 1013)
Csym = mupadmex(op,args{1}.s,
args{2}.s, varargin{:});
Error in - (line 7)
X = privBinaryOp(A, B,
'symobj::zipWithImplicitExpansion',
'_subtract');
Error in THE5 (line 26)
tx1_temp=subs(dif_x1,x1-grad_x1*t);
I keep getting these errors anyone has a clue?Mert Picakcihttps://es.mathworks.com/matlabcentral/profile/authors/14837268tag:es.mathworks.com,2005:Question/7167532021-01-14T09:53:56Z2021-01-17T04:15:07Zhow to find the coefficient ? x1 = cos(2*pi*t);
x2 = sin(2*pi*t);
x3 = sin(2*pi*t + pi/4) ;
x4 = sin(2*pi*t ‐ pi/6) ;
%Note that your results imply that a real sinusoid of arbitrary phase can always be represented as
%the sum of appropriately scaled cosine and sine signals. In particular, determine values for the
%constants A and B such that x3= A*x1 + B*x2, and repeat for signal (vector) x4.
%hint : For x3 & x4, you need to solve first the trigonometric by finding the representation of x3 & x4 from trigonometric function. Below I only show the calculation just for x3. Please find yourself for x4. Once you find the representation then you can code them in Matlab.
% Since x3= A*x1 + B*x2
% sin(2*pi*t + pi/4) = A cos(2*pi*t) + B sin(2*pi*t)
% sin(2*pi*t + pi/4) = sin(2*pi*t) cos(pi/4) + cos(2*pi*t) sin(pi/4)
% Thus A= sin(pi/4) and B = cos(pi/4) Azmi Khoohttps://es.mathworks.com/matlabcentral/profile/authors/19965503tag:es.mathworks.com,2005:Question/7189652021-01-17T04:07:36Z2021-01-17T04:07:36Zgray scale image being displayed in colored formatI have few image files which are in the .img format. I want to to analyze those images without converting it to any other formats such as jpg, png etc. I am able to display those images but the image is in colored format. I checked the class of image. It's not an rgb image. I want to display the image without any colors. Any suggestions would be appreciated. Please find my code below:
im=imageload('E:\Zheng Research\Re__SRTC_Access\MalignatCaseSamples\MalignatCaseSamples\TM00000f010b04m_01.img')
% I=imread(im)
I= image(im,'CDataMapping','scaled');
Warid Islamhttps://es.mathworks.com/matlabcentral/profile/authors/9112730tag:es.mathworks.com,2005:Question/7189602021-01-17T03:49:54Z2021-01-17T03:49:54ZHow to make the keyboard keys on the computer unable to be used to input the Matlab GUI calculator.I have made a scientific calculator in the matlab GUI, but I want the keyboard keys on the computer to not be used to input values in the calculator. Can it? if so, how or what does the syntax look like in m files? I need an answer. thank you.Fandri Hiolahttps://es.mathworks.com/matlabcentral/profile/authors/20954347tag:es.mathworks.com,2005:Question/7187252021-01-16T18:39:12Z2021-01-17T03:44:24ZCheck for missing argument or incorrect argument data type in call to function 'bode'I dont know why is not workingJair Alejandro García Cruzhttps://es.mathworks.com/matlabcentral/profile/authors/19740058tag:es.mathworks.com,2005:Question/7188852021-01-17T00:09:56Z2021-01-17T03:42:46Zsyntax limits the input of digit values on the calculator in the matlab GUIi want to make a science calculator on matlab GUI. what is the syntax to limit the digit value to input in the calculator?Fandri Hiolahttps://es.mathworks.com/matlabcentral/profile/authors/20954347tag:es.mathworks.com,2005:Question/5439622020-06-07T17:04:17Z2021-01-17T03:41:53ZAWGN function snr parameterHi,
could someone explain to me please, why increasing the value of 'snr' parameter of awgn() function results in the outcoming signal being closer to the original (less interrupted). As far as I know, the bigger the SNR, the more interrupted the signal should be.
If the noise is 20dB, the resulting signal should be worse than in case of 10dB noise, isn't it?
Could someone explain why does it work this way?
edit: yeah im stupidMarcin Kolaczhttps://es.mathworks.com/matlabcentral/profile/authors/11421319tag:es.mathworks.com,2005:Question/3309022017-03-20T18:06:21Z2021-01-17T03:36:38ZCounting consecutive values in a matrix Hello,
I'm having trouble keeping tally of my 1's and 0's within a matrix. I simulated a coin flip lets say a 100 times. It'll list values within a (100,1) matrix. I want to create some loops that will count how many one's in a row and how many zeros in a row and it'll alternate. For example lets say A = [1,0,1,1,1,0,0,0,0,1,0,0,1....] so the result would yield B = [1,1,3,4,1,2,1...] Thanks!John Thomashttps://es.mathworks.com/matlabcentral/profile/authors/9981425tag:es.mathworks.com,2005:Question/7189552021-01-17T03:33:34Z2021-01-17T03:35:07ZHow do I further compute hermitian symmetry IFFTHi,
I want to ask what's the difference between computing IFFT from a hermitian-symmetrical complex matrix, when
1st matrix (lets call it X) is created by making a matrix [0, x, 0, fliplr(conj(x)] and then simply -> ifft(X)
2nd matrix (also X) is just computed by adding 'symmetric' flag to ifft -> ifft(X,'symmetric')
The 1st output is longer (twice + 2 zeroes) and I have no idea how to process the signal further.
Which method performs better? Marcin Kolaczhttps://es.mathworks.com/matlabcentral/profile/authors/11421319tag:es.mathworks.com,2005:Question/3033692016-09-17T02:44:16Z2021-01-17T03:20:03ZMEX cannot find a supported compiler in MATLAB R2015b after I upgraded to Xcode 8.0I installed Xcode 8.0 on my Mac and tried to use MEX. But I received the following error at the MATLAB command prompt. Please help, thanks.
>> mex -setup
Error using mex
No supported compiler or SDK was found. For options, visit
http://www.mathworks.com/support/compilers/R2015b/maci64.html.Nan Yehttps://es.mathworks.com/matlabcentral/profile/authors/7789073tag:es.mathworks.com,2005:Question/7189302021-01-17T02:36:06Z2021-01-17T03:09:57ZRecord best solution in each GA generation running with UseParallel=trueHello,
Is there a way to record the best solution at each generation running with parallelization? (that is, with UseParallel=1)
I used outputFcn_global (from File Exchange), but it uses a global variable to record the info. In each generation, I would like to use the output function to just record the best solution (e.g. 1x1000 array) in the population. Since my objective function is a combination of several things, I need the best solution of each generation to then calculate the value of each term in the fitness function separately, and see how the objectives evolve over the generations.
Is there a way to do that without global variables?Tarohttps://es.mathworks.com/matlabcentral/profile/authors/6417293tag:es.mathworks.com,2005:Question/2465072015-10-02T04:00:00Z2021-01-17T03:09:44ZWhy can't MEX find a supported compiler in MATLAB R2015b after I upgraded to Xcode 7.0?I installed Xcode 7.0 on my Mac and tried to use MEX. I receive the following error at the MATLAB command prompt:
ERROR: >> mex -setup
Error using mex
No supported compiler or SDK was found. For options, visit
http://www.mathworks.com/support/compilers/R2015a/maci64.html
Why does MATLAB not recognize the Xcode 7.0 installation on my Mac?MathWorks Support Teamhttps://es.mathworks.com/matlabcentral/profile/authors/4622813tag:es.mathworks.com,2005:Question/7189402021-01-17T02:53:10Z2021-01-17T03:08:31ZFitting experimental data to spring damper ODEHello All,
I am trying to fit an experimental data to an ODE system. Let’s say I have a fluid system which I have found the real time force balance. I have also experimental data providing location and velocity of the fluid parcel of interest. I would like to model this as spring damper ODE.
Here is conversion of the ODE to system of 1st order ODE:
I have seen answers like Parameter Estimation for a System of Differential Equations or Fitting experimental data to an ODE model. However, none of these have non homogenous ODE (in my case having extra force term). The objective is to find k,b,m assuming I have x(t),xdot(t), and f(t).
Here is a piece of code I put together for homogenous problem. I wonder if someone can guide me how I can add the force term to the optimization problem.
global time X xi pi
time= Data.Time(locs:end); %time
X=[Data.location, Data.velocity] %Data
xi= [Data.location(1), Data.velocity(1)]'; %initial values
pi= [1 1]'; %initial parameter guess
opt = fminsearch(@(p) optim(time,X,p,xi), pi); %optimization
function dxVec = ODEFunc(p,t,xVec)
r1= xVec(2);
r2= (-(p(1)/p(3)) * xVec(1) - (p(2) * xVec(2)));
dxVec = [r1;r2];
end
function SSE = optim(time,X,p,xi)
global time X xi
f = @(t,xVec) ODEFunc(p,t,xVec);
[tm, xVecm] = ode45(f, time, xi); %prediction
err = X - xVecm;
SSE = sum(err.^2); %sum squared-error.
endsina rafatihttps://es.mathworks.com/matlabcentral/profile/authors/9281553tag:es.mathworks.com,2005:Question/7189452021-01-17T03:03:36Z2021-01-17T03:03:36ZUser-defined matlab function does not return the right result when run from PythonHi everyone,
I wrote a function in Matlab R2020b then run it in Python using Matlab Engine API. However, for the same function arguments, the result returned from Python is different from the result returned by running the function in Matlab. The function is the following
function P = P_sinr(M,N_users,gamma_th,rho)
% Notice that this function is only used to calculate the probability
% that the SINR is larger than threshold in the GRANT-BASED segment
ratio = gamma_th/rho;
K = floor(N_users - 1);
P = 0;
for p = 0:1:M-K-1
P = P + exp(-ratio)*1/factorial(p)*ratio^p;
end
end
I tried to run it with M = 50, N_users = 20, gamma_th = 6.309, rho = 1.2589. Matlab returns 1, which is correct. However, Python returns 0, which is incorrect.
Any help will be appreciated.Tuong Nguyenhttps://es.mathworks.com/matlabcentral/profile/authors/14525156tag:es.mathworks.com,2005:Question/7179602021-01-15T14:35:11Z2021-01-17T02:56:42ZLoop for randomisation assignment in table columnsI have imported a spreadshet and 'extracted' some certain columns from and made a table with them.
T=readtable(fullfile(datapath,filename), 'Sheet', sheet_name)
T(:, [1,27,28,31,49,59:76])
Now, I need to add 6 columns at the back of the new table named A to F. One of the existing columns contains a randomisation conditions. Depending on which condition (1 or 2) is assigned to each subject, I now need the the A to F lines be filled out with two different orders, e.g. for 1 the lines should be filled out with WE, BC, CCC, LB, RO, NN (see picture).
I thought about making a for or if loop for the two conditions but I don't undertsand how to access the randomisation column and fill it out in the right way.Fee Arnoldhttps://es.mathworks.com/matlabcentral/profile/authors/20586006tag:es.mathworks.com,2005:Question/7189352021-01-17T02:53:04Z2021-01-17T02:53:04ZHello everyone.How can I use the following method to write code to extract dominant points? Thank you all very much. Or if there is a similar code, can you recommend it to me?Dominant point extraction:
Wesleyhttps://es.mathworks.com/matlabcentral/profile/authors/19428999tag:es.mathworks.com,2005:Question/7189252021-01-17T02:16:56Z2021-01-17T02:50:49Zhow to make nan turn into 0 in arrayHello all,
im working in simulink with findpeaks and I have the code as below, for the condition if u ~ = 0 it works well, so the else condition is in the condition if u == 0,
but then there is a nan value outside u ~ = 0 so you need to add elseif,
but when I tried with isnan (u) it couldn't detect that he was nan and I wanted to change it to all 0 values
so that there is an error as shown below,
can anyone help me find out where it went wrong thank you very much
function [dist,peak2,locs2] = fcn(u)
locs = zeros(size(u));
pks = zeros(size(u));
if u ~= 0
[pks,locs] = findpeaks(u);
elseif isnan(u)
locs(size(u))= 0;
pks(size(u)) = 0;
else
locs(size(u))= 0;
pks(size(u)) = 0;
end
a = locs(2)- locs(1);
b = pks(1);
c = locs(1);
dist = a;
peak2 = b;
locs2 = c;
Naufal Arfanihttps://es.mathworks.com/matlabcentral/profile/authors/17333398tag:es.mathworks.com,2005:Question/7189102021-01-17T01:37:56Z2021-01-17T02:27:50ZHow can I do a Matlab report?We have to submit a Matlab (my worst module) assignment to show the heat transfer on a plate. However, I have the 2 codes almost done but I am struggling to write the report. To calculate the temperature on a 2D aluminum plate we need to use the Explicit Finite Difference Method. The problem comes now when I read the task description, which is the following one:
*Table of contents
*Introduction to the problem under consideration
*The constitutive equation of the problem
*Description of the numerical method chosen to discretize the constitutive equation
*The initial and boundary conditions implemented
*Details of your Finite Difference Method
*Analysis of the code....... (I understand everything else from here)
This is what I don't understand and what I don't know if I have done properly:
**The constitutive equation of the problem (On here I explained TAYLOR SERIES and the HEAT TRANSFER)
**Description of the numerical method chosen to discretize the constitutive equation (On here I have explained the Explicit Finite Difference Method and numerical differentiation)
***Details of your Finite Difference Method (I don't even know what I have to do on here)Hdezhttps://es.mathworks.com/matlabcentral/profile/authors/14618863tag:es.mathworks.com,2005:Question/7182902021-01-16T01:29:21Z2021-01-17T02:15:15ZError using findpeaks Expected Y to be one of these types: double, single Instead its type was table.Hi,
I am trying to read a file and find its peak. But the findpeak function keeps throwing errors. Please help. I am new to matlab.
%clear,clc
readtable('KD.xlsx');
x=qw(:,1);
y=qw(:,2);
%y=data(:,2');
Peaks=findpeaks(ans);
[pks,locs] = findpeaks(KD);
plot(x,y,y(locs),pks,'or')
xlabel('Xvalue')
ylabel('Peak')
axis tight
error message:
Error using findpeaks
Expected Y to be one of these types:
double, single
Instead its type was table.
Error in findpeaks>parse_inputs (line 199)
validateattributes(Yin,{'double','single'},{'nonempty','real','vector'},...
Error in findpeaks (line 136)
= parse_inputs(isInMATLAB,Yin,varargin{:});
Error in Untitled (line 6)
Peaks=findpeaks(ans);Venkatakrishnan Rengarajanhttps://es.mathworks.com/matlabcentral/profile/authors/17562691tag:es.mathworks.com,2005:Question/7187652021-01-16T19:11:07Z2021-01-17T02:08:15ZWay to find common eigen vectors for a pair of matrices with known eigen valuesHello,
I am looking for finding or rather building common eigenvectors matrix X between 2 matrices A and B such as :
AX=aX
with "a" the diagonal matrix corresponding to the eigenvalues
BX=bX
with "b" the diagonal matrix corresponding to the eigenvalues
where A and B are square and diagonalizable matrices.
I took a look in a similar post but had not managed to conclude, i.e can't have valid results when I build the final wanted endomorphism F defined by :
F = P D P^-1
I have also read the wikipedia topic and this interesting paper but couldn't have to extract methods pretty easy to implement.
How can I build these common eigenvectors and finding also the eigenvalues associated? I am a little lost between all the potential methods that exist to carry it out.
The screen capture below shows that the kernel of commutator has to be different from null vector :
From another maths forum, one advices me to use Singular values Decomposition (SVD) on the commutator [A,B], that is in Matlab doing by :
"If 𝑣 is a common eigenvector, then ‖(𝐴𝐵−𝐵𝐴)𝑣‖=0. The SVD approach gives you a unit-vector 𝑣 that minimizes ‖(𝐴𝐵−𝐵𝐴)𝑣‖ (with the constraint that ‖𝑣‖=1)"
So I have extracted the approximative eigen vectors V from :
[U,S,V] = svd(A*B-B*A)
1) Is there a way to increase the accuracy to minimize ‖(𝐴𝐵−𝐵𝐴)𝑣‖ as much as possible ?
IMPORTANT REMARK :
I saw there is another function called
rref
which can accept a tolerance parameter but :
1.1 What's the difference with singular values decomposition SVD algorithm ?
1.2 If this routine is efficient, which criterion could I apply for a pertinent choice of this tolerance value
2) Are there other alternative algorithms that could give better results than SVD and rref ?
I know there is not in my case analytical to find a common eigen vectors basis but with a relative small tolerance,
we may find an approximative basis. By the way, I didn't find any documentation about this.
The 2 matrices to find approximative common eigen vectors matrix are available in attachment.
3) If it is possible, Could anyone try to apply a function Matlab appropriate to find a basis of common eigen vectors or write a small Matlab script for this ?
Even a simple approximation would be enough, everything depends of the tolerance that we are ready to accept but currently I don't know how to introduce this tolerance parameter with `SVD` algorithms (if there are different versions in SVD algorithm) or alternative algorithms.
Any suggestion/track/clue/help is welcome
Best Regards
tags: matrix, matrix manipulation , minimization problem, eigen vectors, eigen values, SVD algorithm, nullspace, basis of vectors.petithttps://es.mathworks.com/matlabcentral/profile/authors/2058077tag:es.mathworks.com,2005:Question/7189202021-01-17T01:53:28Z2021-01-17T01:53:50Zcannot install matlab ubuntui got this message everytime tried to install matlab
We are unable to offer you a trial. If you believe you are receiving this message in error, please contact your local customer support representativesam mohelhttps://es.mathworks.com/matlabcentral/profile/authors/20947575tag:es.mathworks.com,2005:Question/470822012-08-31T01:56:19Z2021-01-17T01:51:15ZIs it at all possible to use the 'range' option in xlsread in Matlab 2012a on a Mac?Hi,
I recently changed from Windows to a Mac-system and I've been trying to somehow import data from an excel file while using the 'range' option in xlsread. I'm running Mountain Lion, Matlab 2012a for Mac and Excel for Mac 2011.
I found heaps of help on Matlab Central. A few workarounds were mentioned for this kind of problem. I tried the standard
[num,txt,raw] = xlsread('example_mac.xls',1,'C3:E5');
which resulted in
Warning: Range cannot be used in 'basic' mode. The entire sheet will be loaded.
> In xlsread at 199
and then I found a suggestion here
http://www.mathworks.com/matlabcentral/answers/43872-alternative-to-xlsread-from-website-data-on-mac-matlab-r2012a
which suggested the command
A = dataset('XLSFile','example.xls','Sheet','T0NSW.1','Range','C2:E5');
which again resulted in this warning
Warning: Range cannot be used in 'basic' mode. The entire sheet will be loaded.
> In xlsread at 199
In dataset.readXLSFile at 14
In dataset.dataset>dataset.dataset at 344
I thought that the functionality of xlsread would be somewhat more general from 2012a onwards. I somehow understood that xlsread would available in the general mode and not just the basic mode, but I might have misunderstood that.
The xls-files I'm using are Excel 97-2003 files, I re-saved them all on the Mac system using Excel for Mac 2011.
*The only question I have is:*
*Can I somehow import data from an Excel file while defining a specific range within the file?*
Is there a workaround for this? If yes, a link to the solution would be sufficient. I looked for about a day now and I can't find a solution.
Thank you very much,
ArneArnehttps://es.mathworks.com/matlabcentral/profile/authors/1623336tag:es.mathworks.com,2005:Question/987272009-06-27T01:12:00Z2021-01-17T01:12:30ZHow do I convert an image to grayscale format and print to eps format in MATLAB 7.6 (R2008a)?I need to print figures in eps format in grayscale. If I use the command
print('-deps',figname(i))
my figure is cropped correctly and has all of the correct tick limits, etc., but is only in black and white.MathWorks Support Teamhttps://es.mathworks.com/matlabcentral/profile/authors/4622813tag:es.mathworks.com,2005:Question/7188602021-01-16T22:36:39Z2021-01-17T01:02:44ZHow do I find the indices of NaN values in a cell array?Hi, I have a 3390 x 1 cell array containing 4 x 30 doubles. Some of these doubles contain NaN values which I would like to replace by the preceding double. How do I detect the indices of the doubles containing 'NaN' values and then replace them with the preceding 4x30 double? I have attached the cell array in question. Thanks in advance. Cai Chinhttps://es.mathworks.com/matlabcentral/profile/authors/18969819tag:es.mathworks.com,2005:Question/7188752021-01-16T23:39:56Z2021-01-17T00:49:00ZMatlab does not plot the functionI'm trying to plot this function. There is no syntaxis mistakes, but the graphic appears empty. (It is a bode diagram).
GH_num= [1 2 3];
GH_den= [4 5 6 7 8];
GH_w=[];
for w=2*pi*logspace(-1,3,1000)
GH_num_w=polyval(GH_num,w*j);
GH_den_w=polyval(GH_den,w*j);
GH_w=[GH_w,GH_num_w/GH_den_w];
end
mag = 20*log10(abs(GH_w));
phase=rad2deg(angle(GH_w));
fGH=figure;
aGH=subplot(2,1,1,'Parent'fGH);
bGH=subplot(2,1,2,'Parent'fGH);
semilogx=(aGH,w/2/pi,mag)
semilogx=(bGH,w/2/pi,phase)
Inés Bodoquehttps://es.mathworks.com/matlabcentral/profile/authors/11965162tag:es.mathworks.com,2005:Question/7188802021-01-17T00:07:59Z2021-01-17T00:47:08ZCode Segment works in Command Window but not in scriptError Message: "Incorrect dimensions for matrix multiplication."
Variables: X(5000 x 400) and theta (10 X 400);
Code: prob = X * theta';
This code works in the command window but when I try to run this segment of code in a script it gives me the shorten-error message above. Any suggestions on how to make the code run in the script? Vista Marstonhttps://es.mathworks.com/matlabcentral/profile/authors/19129330tag:es.mathworks.com,2005:Question/7189052021-01-17T00:43:25Z2021-01-17T00:43:25ZAssigning values in a vector array to a column in an arrayHello,
I have a column vector of size 20073 x 1 from a previous model output (the steady state run), and I would like to copy all the values from the column vector into the corresponding indices of the first column of an array of size 20073 x 688 in my transient run. After that first column in the array is populated, I want to fill the rest of the array with values that I calculate in the latter part of the for loop. However, I keep running into matrix size, compatibility, and index errors.
I have attached the code I am having probems with (non_steady_state_thick_change.m). I have written a similar code for the steady state run (thick_change_spatially_var.m, attached), but I don't run into any errors and the code runs without any problem.
Here are some sizes and properties of the variables in the functions:
In thick_change_spatially_var.m (corresponding to the steady state run)
store_thickness = zeros(length(xy),length(pt.out_t)); % the size of xy is 20073 x 2, pt.out_t is 1 x 334, so store_thickness is 20073 x 334
surf_test = zeros(length(xy),length(pt.out_t));% the size of xy is 20073 x 2, pt.out_t is 1 x 334, so store_thickness is 20073 x 334
dt = pt.out_t(2) - pt.out_t(1); %30 days, in seconds
thinning_rate_downglacier = 1/pp.year; %pp.year is seconds per year
thinning_rate_upglacier = 0.5/pp.year;
pp.topo.slope_factor % 1x1 double
In non_steady_state_thick_change.m (corresponding to the transient run
store_thickness = zeros(length(xy),length(pt.out_t)); %the size of xy is 20073 x 2, pt.out_t is 1 x 668, so store_thickness is 20073 x 668
surf_test_transient = zeros(length(xy),length(pt.out_t));%the size of xy is 20073 x 2, pt.out_t is 1 x 668, so store_thickness is 20073 x 668
dt = pt.out_t(2) - pt.out_t(1);
thinning_rate_downglacier = 1/pp.year;
thinning_rate_upglacier = 0.5/pp.year;
% pin.ice_thickness_surf_start_val : ice_thickness_surf_start_val is 20073 x 1
Does anyone have any suggestions?
Thanks!Anna Haydenhttps://es.mathworks.com/matlabcentral/profile/authors/6918139tag:es.mathworks.com,2005:Question/7189002021-01-17T00:42:08Z2021-01-17T00:42:08ZDiscretization method used in MPCWhich discretization method is used in MPC toolbox?Hossam Elwanhttps://es.mathworks.com/matlabcentral/profile/authors/17249108tag:es.mathworks.com,2005:Question/7188952021-01-17T00:23:17Z2021-01-17T00:36:11ZHow to change color in Graph (jet) I copied and pasted the following code that describes a Fourier Series
% Define domain
dx = 0.001;
L = pi;
x = (-1+dx:dx:1)*L;
n = length(x); nquart = floor(n/4);
% Define function
f = x;
plot(x,f,'-k','LineWidth',1.5), hold on
% Compute Fourier series
CC = jet(20);
A0 = sum(f.*ones(size(x)))*dx;
fFS = A0/2;
for k=1:20
A(k) = sum(f.*cos(pi*k*x/L))*dx; % Inner product
B(k) = sum(f.*sin(pi*k*x/L))*dx;
fFS = fFS + A(k)*cos(k*pi*x/L) + B(k)*sin(k*pi*x/L);
plot(x,fFS,'-','Color',CC(k,:),'LineWidth',1.2)
end
legend('Function: f(x) = x',...
'Terms: N = 20','Interpreter','latex','Fontsize',16,...
'Location','northwest')
I noticed, that the color of "Terms" in legend is always blue (so k = 1). However, I want it to be the color of the kth Function, im my case k = 20.
How to achieve that? A common problem with coppied function. Niklas Kurzhttps://es.mathworks.com/matlabcentral/profile/authors/18516014tag:es.mathworks.com,2005:Question/6914202020-12-12T01:14:41Z2021-01-17T00:35:11ZSolving system of ODEs using Euler's method Hello everyone,
I need to model a trajectory of a flying object and this process is described by a system of two 2nd-order ODEs. I have already reduced it to a system of four 1st-order ODEs:
with z1(0)=0, z2(0)=Vcosα, z3(0)=0, z4(0)=Vsin(α) while k is 0.1, m is the mass of the object, g is 9.8, V is the initial velocity and α is the launch angle.
I have only practcied solving a single 1st-order of ODEs using Euler's method before so I don't really get the hang of this problem. Could anyone please help me to solve this problem in the simplest way possible?
Many thanks!Nobita Nobihttps://es.mathworks.com/matlabcentral/profile/authors/15009035tag:es.mathworks.com,2005:Question/7188902021-01-17T00:15:21Z2021-01-17T00:27:47ZHow to log image data acquired by imaqtool to disk with repeated triggers.Here's an example code from the documentation, which waits for 100 triggers and acquires 5 frames for each trigger. I wonder how to log the image data into disk during the acquisition? I know we can get all data after the acqusition, such as data = getdata(vid,nFrames). However if the acqusition is long, it may run out of the memory, right? How to log image data into disk during the acquisition with repeated triggers?
% Create video input object.
vid = videoinput('dcam',1,'Y8_1024x768')
% Set video input object properties for this application.
vid.TriggerRepeat = 100;
vid.FramesPerTrigger = 5;
% Set value of a video source object property.
vid_src = getselectedsource(vid);
vid_src.Tag = 'motion detection setup';
% Create a figure window.
figure;
% Start acquiring frames.
start(vid)
% Calculate difference image and display it.
while(vid.FramesAvailable >= 2)
data = getdata(vid,2);
diff_im = imabsdiff(data(:,:,:,1),data(:,:,:,2));
imshow(diff_im);
drawnow % update figure window
end
stop(vid)Yuhan Yanghttps://es.mathworks.com/matlabcentral/profile/authors/11541561tag:es.mathworks.com,2005:Question/3173992016-12-19T03:56:43Z2021-01-17T00:06:25ZCount number of consecutive 1's within a blockIf x= 0 0 0 0 1 1 1 1 0 1 1 1 0 1 1 0 1 0 then the intended output would be y=4 3 2 1. It would also be useful if I had someway of knowing when each group started, as in 4 having begun at the 5th point and 3 at the 10th etc.
Many thanks in advance!DoyleDkhttps://es.mathworks.com/matlabcentral/profile/authors/9389774tag:es.mathworks.com,2005:Question/7175852021-01-15T04:45:54Z2021-01-17T00:01:10ZRemove black pixels from RGB image.I know that variations of this question get asked a lot on here, but I haven't found a solution that works for my problem very well.
How do I remove the black border from the image above programmatically, but not by using imcrop!? I would prefer to find & remove all of the black pixels in the image, by effectively deleting that data--leaving me with a (yes) cropped image that contains only the color region of this image. My attempt is as follows:
% define scale bar:
firstFrame = read(vidObj,1);
imshow(firstFrame,'InitialMagnification',300);
title('Define the scale bar region:','FontSize',16);
scaleBar = drawrectangle('Color',[1 1 0]);
roi_Bar = scaleBar.Position;
% cropped and screwed:
I = imcrop(firstFrame, roi_Bar);
figure;
imshow(I);
% remove black border:
mask = (I(:, :, 1) == 0) & (I(:, :, 2) == 0) & (I(:, :, 3) == 0);
I(mask) = [];
figure;
imshow(I); % this returns a horrific result
Many thanks in advance! Luke G.https://es.mathworks.com/matlabcentral/profile/authors/11209081tag:es.mathworks.com,2005:Question/7182152021-01-15T22:25:14Z2021-01-16T23:51:32ZWhat is the Fourier Function of Matlab doing? Hidden in the Matlab basic functions I discovered
fourier(f)
existst. This seems useful I thought, because It applies the fourier-transform to the function f by calculating the complex integral.
But how can I take use of that? I thought, by doing the transform, I can simply plot it:
syms x
FT = fourier(x^2)
fplot(FT)
isn't doing much. Is there a misunderstanding at the root? Niklas Kurzhttps://es.mathworks.com/matlabcentral/profile/authors/18516014tag:es.mathworks.com,2005:Question/7104882021-01-06T21:10:13Z2021-01-16T23:50:13ZHow can I augment a toolbox to improve its capabilities?I am using the Robotics Systems Toolbox and its rotm2eul() function only takes in 3 possible rotation orders, XYZ, ZYX, and ZYZ. With permutations of these types there are 12 possibilities and matlab only works with a quarter of them. Adding support for the others is trivial thanks to the intelligent way the others were programmed. I only need to add 9 lines of code and remove a number of duplicated code statements in various code blocks.Andrew Roleyhttps://es.mathworks.com/matlabcentral/profile/authors/13023900tag:es.mathworks.com,2005:Question/7182952021-01-16T01:52:22Z2021-01-16T23:41:23Zhow to find coordinate of a puzzle piece?I try to determine the coordinates of a puzzle piece on the original image using the normxcorr2 function. Then I draw a rectangle on the correspondence of the two elements. Unfortunately, I notice that the coordinates that this match has given me are not good. Could someone have an idea how to improve the use of this feature and get some better results.
The puzzle piece has the name "cpiece" and the original picture has the name "bild"
clear all;
close all;
clc
cpiece = im2gray(imread('cpiece1.jpg'));
bild = im2gray(imread('original.jpg'));
figure(1)
montage({bild,cpiece})
c = normxcorr2(cpiece,bild);
figure(2)
surf(c)
shading flat
[ypeak,xpeak] = find(c==max(c(:)));
yoffSet = ypeak-size(cpiece,1);
xoffSet = xpeak-size(cpiece,2);
figure(3)
imshow(bild)
drawrectangle(gca,'Position',[xoffSet,yoffSet,size(cpiece,2),size(cpiece,1)],'FaceAlpha',0);Tiodong Nongni Gilles Patrickhttps://es.mathworks.com/matlabcentral/profile/authors/20713099tag:es.mathworks.com,2005:Question/7188702021-01-16T23:06:27Z2021-01-16T23:06:27ZSignature algorithm for character recognitionI have a group of images that include characters (A, B, Y, T, 1,2,3,4,5,6) and I do segment them and need a way to recognise them without using the built in ocr function. So, I considered sift or signature method for recognition. So, any help on how to implement the signature method to identify the stated letters?
thanks.
Vague Shadowhttps://es.mathworks.com/matlabcentral/profile/authors/20243007tag:es.mathworks.com,2005:Question/7179202021-01-15T13:34:09Z2021-01-16T23:04:12ZKeeping track of the Index while using "cell2mat" functionhey guys, I have a Cell Array a and am using cell2mat function for further clustering analysis, lets say:
a = {[1 2 3; 7 8 9], [4 5 6;10 11 12; 13 14 15]};
b = cell2mat(a(:));
rng(2)
k=2;
[idx] = kmeans(b,k);
which_in_cluster = cell(k,1);
for j = 1:k
which_in_cluster{j} = find(idx == j);
end
Cluster_1 = b(which_in_cluster{1,1},:); % 1st Cluster
Cluster_2 = b(which_in_cluster{2,1},:); % 2nd Cluster
Cluster_1 =
7 8 9
10 11 12
13 14 15
Cluster_2 =
1 2 3
4 5 6
I am now looking for a way to know in which Cell number and row these clusters have originally been in a. So in this example:
Cluster_1 =
7 8 9 % This has been in Cell number 1, row index 2 of a
10 11 12 % This has been in Cell number 2, row index 2 of a
13 14 15 % This has been in Cell number 2, row index 3 of a
Any help is greatly appreciated.Ko Fahttps://es.mathworks.com/matlabcentral/profile/authors/9991682