https://kr.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2019-02-18T14:12:09Ztag:kr.mathworks.com,2005:Question/4454352019-02-17T17:30:34Z2019-02-18T14:12:09ZHow can I group column of data with the same time stamp and get the row mean of each group?
from this table to this image where
x = Height
t = time
u = zonal wind
Teddy2018https://kr.mathworks.com/matlabcentral/profile/authors/14804435-teddy2018tag:kr.mathworks.com,2005:Question/4040952018-06-05T09:58:57Z2019-02-18T14:10:28ZRecharge and recovery braking energy.In a model having a battery, the electric motor supplying a dynamic load, passes through braking phases.
I am looking for examples on simulink matlab 2015a, on the design of a command capturing the deceleration of the speed, and the deminution of the level of the SOC of the battery, in order to recharge the latter. how to make a loop having a battery charging output.
cordially.
S. BELHADJ.said belhadjhttps://kr.mathworks.com/matlabcentral/profile/authors/7262082-said-belhadjtag:kr.mathworks.com,2005:Question/4455822019-02-18T14:10:22Z2019-02-18T14:10:22ZHelp with Matlab code-pleaseGood afternoon,
I am trying to run the following code in MATLAB but get an error.
Error using *
Inner matrix dimensions must agree.
Error in vcqr (line 27)
e = y - x*bhat; % Generate residuals
Any help to fix the problem please?
Thanks
Oz
clear
load fish1
Z = [ones(111,1) stormy mixed];
X = [ones(111,1) d];
pihat = inv(Z'*Z)*(Z'*d);
tau = ['15';'25';'35';'45';'50';'55';'65';'75';'85'];
for i = 1:size(tau,1),
disp(i);
hamster = str2num(strcat('.',tau(i,:)));
boo = rq([ones(size(y)) Z*pihat],y,hamster);
[b,vc] = vcqr(boo,y,[ones(size(y)) Z*pihat],hamster);
[b,f,c,seq,conv] = mcmc_flat_fish1_mon2('iqrobj_fish',boo,vc,50000,y,[ones(size(y)),d],Z,hamster);
save(strcat('fish',tau(i,:),'_storm_v3_mon2'),'b','f','c','seq','conv');
[b,f,c,seq,conv] = mcmc_flat_fish2('iqrobj_fish',boo,vc,50000,y,[ones(size(y)),d],Z,hamster);
save(strcat('fish',tau(i,:),'_storm_v3_2'),'b','f','c','seq','conv');
end
% Here is the portion of the function related to the error:
vc = zeros(k,k);
b = zeros(k,2);
S = (1/n)*x'*x;
e = y - x*bhat; % Line 27Ozmandohttps://kr.mathworks.com/matlabcentral/profile/authors/2950000-ozmandotag:kr.mathworks.com,2005:Question/4455542019-02-18T11:39:40Z2019-02-18T14:08:29ZWhat is the equivalent of the function 'wait' after using 'imellipse' for the new function 'drawcircle' (version R2018b)?I am trying to use the new function 'drawcircle' to select a ROI and perform some analysis on a set of images.
Before, with the function 'imellipse', it was possible to interactively place an ellipse by clicking and dragging, then use wait to block the MATLAB® command line and finally double-click on the ellipse to resume execution of the MATLAB command line. See code below.
imshow('coins.png')
h = imellipse;
position = wait(h)
The function 'imellipse' still works but I would like to use the new function 'drawcircle' and do exactly the same. I can't seem to be able to find the solution to block and resume the execution of the command line. Therefore, my code is running to the end without taking into account the position of the modified ROI. DJRhttps://kr.mathworks.com/matlabcentral/profile/authors/4801517-djrtag:kr.mathworks.com,2005:Question/4455722019-02-18T13:36:15Z2019-02-18T14:07:45ZHow to save the output of a loop with sequential file numbers.I am trying to save the output of a simple face detector. I have a group image with multiple faces and want to store cropped images of each face individually, as well as a rotated version of the image. This is a simplified version of the code I am implementing and would be very grateful if someone could help me write the two output images (face_crop and imrotate) to one folder. The file names do not matter. Thank you!
I = imread('my group image')
% bounding_box is size 50
bounding_box = step(vision.CascadeObjectDetector(), I)
for i:size(bounding_box, 1)
% Save this image as 01.jpg (then 03, 05, 07 .... 99)
face_crop = imcrop(I, [227,227])
>>>
% Save this image as 02.jpg (then 04, 06, 08 .... 100)
imrotate = (face_crop, 5, 'bilinear')
>>>
endpldr-bnyhttps://kr.mathworks.com/matlabcentral/profile/authors/13659700-pldr-bnytag:kr.mathworks.com,2005:Question/4423432019-01-30T18:55:35Z2019-02-18T14:07:20ZHow to Apply FFT on CVS file.I am Begnier and have no idea how to apply fast fourier transform. I have vibration data with three columns and it is very large data (length of 215997 )
I want to apply Fast fourier transform on it. I don't know how to start and where to strat.
I collected this data by running my pump 6 hours.
Ahsan Umarhttps://kr.mathworks.com/matlabcentral/profile/authors/10575737-ahsan-umartag:kr.mathworks.com,2005:Question/4455812019-02-18T14:05:26Z2019-02-18T14:05:26ZCan I extend my license to the second PCI have an individual license Mathlab Professional. Can I grant using this license also to one colleague on his PC?Nikolay Voznesenskiyhttps://kr.mathworks.com/matlabcentral/profile/authors/8454132-nikolay-voznesenskiytag:kr.mathworks.com,2005:Question/4455572019-02-18T12:12:39Z2019-02-18T14:05:25Zfind row with certain value and put in cell B=[ 1 2
1 5
2 3
2 4
2 5
3 4
4 5
4 7
4 9
5 6
6 11
6 12
6 13
7 8
7 9
9 10
9 14
10 11
12 13
13 14];
A= [1 0 1 0 1 0 1
1 0 1 0 1 0 1
0 1 0 0 0 0 0
0 1 1 0 1 0 1
1 0 0 0 0 0 0
0 1 0 0 0 0 0
0 0 1 0 0 0 0
0 0 0 1 0 0 0
0 0 0 1 1 0 1
0 0 0 0 1 0 1
0 0 0 0 1 0 0
0 0 0 0 0 1 0
0 0 0 0 0 1 1
0 0 0 0 0 0 0
0 0 0 1 0 0 0
0 0 0 0 1 0 0
0 0 0 0 0 0 1
0 0 0 0 1 0 0
0 0 0 0 0 1 0
0 0 0 0 0 0 1];
res=cell(1,size(A,2));
for i=1:size(A,2)
[row,~]=find(A(:,i)==1);
res{i}=B(row,:);
end
result= cellfun(@(x) unique(x),res,'UniformOutput',false);
I want to get this result={[1,2,5],[2,3,4],[1,2,4,5],[4,7,9],[1,2,4,5,6,9,10,11],[6,12,13],[1,2,4,5,6,9,13,14]}
Naime Ahmadihttps://kr.mathworks.com/matlabcentral/profile/authors/13711668-naime-ahmaditag:kr.mathworks.com,2005:Question/4455802019-02-18T14:01:09Z2019-02-18T14:01:09ZHow can i measure the distance of each pixel of a binary image from a specified co-ordinate?I'm trying to measure error in roundness. I have got a point i.e., the center point co-ordinates(Xc,Yc). Now from this point i have to measure the distance of each pixel of the circle geometry so as to get the mean radius. So can anyone help me?Prathveraj Shettyhttps://kr.mathworks.com/matlabcentral/profile/authors/14207414-prathveraj-shettytag:kr.mathworks.com,2005:Question/4455582019-02-18T12:16:15Z2019-02-18T14:00:27ZIntegration is not evaluated inside a function file Hi
Could you please help with code below. It is not clear to me why the integration does not evaluated inside the function file. when I used script it is worked but I need to simplified the process by creating the func file to call it at different steps. The integration is identified for the variable (b) as presented in the code below:
function Fg=Fg(a)
syms b;
f_UHM=b/(-0.181363336688152-0.637631218835414*b)+2.64004309728928;
diff_f_UHM=diff(f_UHM)
a1=a-2.5;
FF=diff_f_UHM*asin(b/a1)
q1=int(FF,0,a1)
F=subs(f_UHM,a1)
Fg=F-(2/pi)*q1
endWazy skyhttps://kr.mathworks.com/matlabcentral/profile/authors/13323105-wazy-skytag:kr.mathworks.com,2005:Question/4455792019-02-18T13:58:47Z2019-02-18T13:58:47ZCar running over a humpUsing a car of mass 1000Kg, a spring stifness of 5 0000 N/m, a damper coe�ficient of 90000m/1 and a hump with dimensions 1m in width and 30cm high, how can I write a mathematical model on Matlab that display the displacement of the driver?
I worked out these equations for now: time = (humpWidth/2)/velocity
verticalAcceleration = (2*humpHeight)/time^2
forceonTires = carWeight * verticalAcceleration
But I'm stuck here.
Thank you for any help!Valentina Malconihttps://kr.mathworks.com/matlabcentral/profile/authors/13751790-valentina-malconitag:kr.mathworks.com,2005:Question/4455782019-02-18T13:56:03Z2019-02-18T13:56:03ZHow do I apply a 1-D median filter and a moving average filter to this set of data?data = [ 10000 -1.202118049
14918.95558 -0.919568637
22257.52355 -0.332079504
33205.90052 -0.9507341
49539.73548 -0.311056814
73908.11129 -0.234900899
110263.1829 -0.909766624
164501.1528 0.249091768
245418.5391 -1.649532359
366138.8283 -0.890747269
546240.8915 -0.679462154
814934.3596 -0.546853842
1215796.951 -0.375618783
1813842.07 -0.598653135
2706062.927 0.195205505
4037163.26 0.207519359
6023025.934 0.288909309
8985725.636 -0.138220046
13405764.16 0.113403922
20000000 -1.157502068]; %Paste data in here
Geff=q2/7e-9;
Ceff=e2/7e-9;
y = semilogx(f0,re,'b-',data(:,1),factor*data(:,2),'bo');
grid on; axis([1e4 2e7 -0.5 1])Elliza Feisolhttps://kr.mathworks.com/matlabcentral/profile/authors/9673873-elliza-feisoltag:kr.mathworks.com,2005:Question/4454532019-02-17T19:05:21Z2019-02-18T13:55:59ZIs there any way to separate the terms of a product?Hello,
Let's say I have this function_handle: f = @(x) exp(x-2)*log(x)
Is it possible to assign each function that comprises this product to its own seperate variable i.e:
g = exp()
h = x-2
j = log()
k = x
Thank you!Panagiotis Panagopoulos Papageorgiouhttps://kr.mathworks.com/matlabcentral/profile/authors/14804881-panagiotis-panagopoulos-papageorgioutag:kr.mathworks.com,2005:Question/4455772019-02-18T13:55:39Z2019-02-18T13:55:39ZPSD - average & sinc several measurementsHello,
I'm lookong to average the PSD of several measurements with the same Fs and to sincronize measurements with different Fs
For example I took 10 measurements with Fs1=100 and 10 measurements with Fs2=300;
when I plot the PSD of the two signals I get nice overlap bat when I try to use dsp.data & dsp.frequencies the overlap is not good.
How do I overcome this?
thank you
Naama
Naama Gorenhttps://kr.mathworks.com/matlabcentral/profile/authors/14813127-naama-gorentag:kr.mathworks.com,2005:Question/4455312019-02-18T09:08:02Z2019-02-18T13:55:19Zhelp 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 constant.
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 Sowayanhttps://kr.mathworks.com/matlabcentral/profile/authors/8027473-ahmed-sowayantag:kr.mathworks.com,2005:Question/4455752019-02-18T13:43:24Z2019-02-18T13:55:01Z3D plotting in MatlabDear All,
I have three variables,each are vector of ,let's say five elements each,I want to plot the the 3D plot of this vector variables.this might be a silly question but i doubt how to generate the 3D plot of the three variables that are independenat set of vectores with equal dimension.
Any help will be appreciated,
Thank you!Zeabhttps://kr.mathworks.com/matlabcentral/profile/authors/11002181-zeabtag:kr.mathworks.com,2005:Question/4447922019-02-13T16:22:00Z2019-02-18T13:49:53ZChange colour order and restore itHi,
I want to change figure colour order. I use this
co = [0 0.4470 0.7410;
0.85 0.3250 0.098;
0.9290 0.6940 0.1250;
0.4940 0.1840 0.5560;
0.4660 0.6740 0.1880;
0.6350 0.0780 0.1840;
0.3010 0.7450 0.9330];
set(gca,'defaultAxesColorOrder',co)
get(gca,'colororder')
I only change the last row becuase I want this colour before. However, it does not work, I get this
ans =
0 0.4470 0.7410
0.8500 0.3250 0.0980
0.9290 0.6940 0.1250
0.4940 0.1840 0.5560
0.4660 0.6740 0.1880
0.3010 0.7450 0.9330
0.6350 0.0780 0.1840
If I use this
co = [0 1 1;
0 0.5 0;
1 0 0;
0 0.75 0.75;
0.75 0 0.75;
0.75 0.75 0;
0.25 0.25 0.25];
Everything works fine... So, what is wrong?
On the other hand, after change the order (if I could), I want to restore it and I use this:
ax = gca; ax.ColorOrderIndex = 1;
But I could no restore it... I plot a figure and I get the same result that previously...
Any help?
Best regardsLuis Vallejo Castrohttps://kr.mathworks.com/matlabcentral/profile/authors/12983371-luis-vallejo-castrotag:kr.mathworks.com,2005:Question/4455762019-02-18T13:47:17Z2019-02-18T13:47:17ZHow to unhide look under mask arrow in matlab simulink ?I am using matlab 2018b. I created my library but I didn't find that down arrow.Yash Vaidhttps://kr.mathworks.com/matlabcentral/profile/authors/12439386-yash-vaidtag:kr.mathworks.com,2005:Question/4455692019-02-18T13:31:52Z2019-02-18T13:46:22ZHow to reuse function and generate less files using HDL coder I have a simulink design that is very repetetive and uses the same subsystems and blocks multiple times.
The HDL coder is generating a huge number of files, for instance I have multiple Image Filter blocks and the coder generates ,for each of them, a number of files for padding, data memory lines, line buffer.... the project becomes unweildy very quickly with over a 1000 files.
Is there a way to reuse functions and subsystems throughout the project?Allahttps://kr.mathworks.com/matlabcentral/profile/authors/10293991-allatag:kr.mathworks.com,2005:Question/4455462019-02-18T10:54:47Z2019-02-18T13:38:39ZHow can I equate all values of one vector to another and get the value ? Please find the example belowIf I have
dataA = [1,2,3,4,5,6,7,8,9];
dataB = [0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1];
I need to equate for example: 1 = 0.1, 2=0.2, 3=0.3 so that if I ask value(7) it should display 0.7
Thank you in Advance.Rakesh Yadav Kodarihttps://kr.mathworks.com/matlabcentral/profile/authors/10084164-rakesh-yadav-kodaritag:kr.mathworks.com,2005:Question/4449832019-02-14T15:44:28Z2019-02-18T13:37:55ZHow to loop multiple images in a subplot?I've saved 4 pictures in 4 variables that means 4 pictures per variable. I'd like to subplot all those pictures (16 pictures) in a loop. Kindly, help me through this.Talha Anwerhttps://kr.mathworks.com/matlabcentral/profile/authors/9402865-talha-anwertag:kr.mathworks.com,2005:Question/4455742019-02-18T13:37:34Z2019-02-18T13:37:34Zunderstand and generate random data using copula statisticsHello everyone,
I need help for something on copula and I do not know much. In fact, I have historical rainfall data from which I calculated an index the SPI, (standardized precipitation index) which is a statistical indicator comparing the total precipitation received at a particular location during a period of n months with the long-term rainfall distribution for the same period of time at that location. [The SPI is calculated on a monthly basis for a moving window of n months, where n is the rainfall accumulation period, which is generally 1, 3, 6, 9, 12, 24, or 48 months. The corresponding SPIs are given as SPI-1, SPI-3, SPI-6,…, and SPI-48. To allow for the statistical comparison of wetter and drier climates, SPI is based on a transformation of the accumulated precipitation into a standard normal variable with zero mean and variance equal to 1. Negative SPI values denote rainfall deficit, whereas positive SPI values indicate rainfall surplus.]
The process is first to select dry events (SPI<-1) and determine 4 parameters (starting month. duration, averageSPI and minimumSPI). Then it is said that the occurrence of historical drought events can be translated into probability via the univariate marginal distribution of the 4parameters. Then from that there is an algorithm (loop) that is done to randomly generate some daily rainfall values. I attached the related document so that someone can help me understand more and create the script on matlab...Thank youWendso Awa Agathe Ouedraogohttps://kr.mathworks.com/matlabcentral/profile/authors/14812784-wendso-awa-agathe-ouedraogotag:kr.mathworks.com,2005:Question/4455712019-02-18T13:35:45Z2019-02-18T13:37:25ZCan I decide the order of multiplication of symbols? Like with matrix multiplication Hi, I have 4x4 matrix, which looks like this for example:
E = [R*N, 1;
0,1]
B =[M*T, 1;
0,1]
The R, M, N and T within this E matrix are also matrises, but I just want them to remain symbolic, I don't want to write out what R is in matrix form.
So when I multiply E*B I want (R*N) and (M*T) to be multiplied as if they were matrices. What I mean by that is that the order of multiplication is important.
I want E*B to be equal to [(R*N)*(M*T), R*N;
0 , 1]
currently when I do multiplication between E*B, Mathlab treats M, R, N, T as just normal symbols and multiplies them, but the order is not correct. Mathlab sorts them.
Is there a way for me to tell mathlab that the symbols (R*N) and (M*T) is to be treated as matrises? Or at least tell mathlab that the order of multiplication matters?
thanksElise Mari Vigrehttps://kr.mathworks.com/matlabcentral/profile/authors/11006465-elise-mari-vigretag:kr.mathworks.com,2005:Question/4455732019-02-18T13:37:24Z2019-02-18T13:37:24ZTwo webcams simultaneous clickI am doing a project on stereo vision and for that I require two webcams to click the image simultaneously. Using just one button both webcams should capture the image without any time delay between their clicks and save them in two variables. Is there a way to do so in matlab ?Karn Vadaliyahttps://kr.mathworks.com/matlabcentral/profile/authors/14605387-karn-vadaliyatag:kr.mathworks.com,2005:Question/1835062015-03-16T19:43:16Z2019-02-18T13:35:37ZDoes NI-DAQ support standalone deployment?So, here's the issue I'm having:
I've written and tested a GUI that reads from an NI USB-6009 adapter. This program works on my Windows 7 PC, with MATLAB both 2015A and 2014B, and I've installed the NI-DAQmx 14.0 driver.
The problem is, it's not working on the laptop that I ultimately have to deploy the application to. I compiled the GUI on my PC, and then installed it and the MCR on the laptop (running Windows 7), and the same NI-DAQmx 14.0 driver as well.
When I run the GUI as a standalone on my PC, it still works. But it doesn't even detect NI as a vendor when I try to run the standalone on the laptop, even though NI-MAX and Windows both detect the USB-6009 device. So, my question is, is there any incompatibility with the MCR and DAQ toolboxes that would cause this?Davehttps://kr.mathworks.com/matlabcentral/profile/authors/2164997-davetag:kr.mathworks.com,2005:Question/3406132017-05-17T04:00:00Z2019-02-18T13:34:36ZHow do I deploy MATLAB code which makes use of Data Acquisition Toolbox with a third party vendor?I have written MATLAB code which uses the Data Acquisition Toolbox in combination with Data Translation hardware. I have installed the Data Translation Data Acquisition Toolbox for this and everything works fine in MATLAB. I now want to use MATLAB Compiler to deploy my MATLAB code as a standalone application. When I try to run the standalone application I receive the following error though:
ERROR: The vendor 'dt' is not known. Use 'daq.getVendors()' for a list of vendors.
MathWorks Support Teamhttps://kr.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:kr.mathworks.com,2005:Question/710012013-04-08T14:31:23Z2019-02-18T13:33:50ZStandalone executiable won't work properlyHi all,
I created a program with a GUI, the goal is to output signals to different devices (3) using a NationalInstruments Data acquisition card.
First thing you have to know is that everything works well when i'm using it INSIDE Matlab.
but after compiling with mcc -mv main.m -a *, the standalone .exe don't have the same behaviour.
As an example, The first thing the program have to do is to verify if the device is connected (USB) using a try/catch structure. But even if the device is connected, the program throw me the error message in 'catch'.
In my opinion, there's probably an issue whit the compiler because everything is fine inside Matlab but I wonder what the problem could be...
I'm using Matlab R2012b and compiler version 4.18
Thanks in advance.
Maxime Jardonnethttps://kr.mathworks.com/matlabcentral/profile/authors/3387255-maxime-jardonnettag:kr.mathworks.com,2005:Question/4455702019-02-18T13:31:54Z2019-02-18T13:31:54ZTesting Calibrated Cameras using MatlabI am doing a poject on stereo vision. I have calibrated two webcams using the matlab calibration app, I want to check whether the cameras are perfectly calibrated or not. Is there a way I can check that using matlab ?Karn Vadaliyahttps://kr.mathworks.com/matlabcentral/profile/authors/14605387-karn-vadaliyatag:kr.mathworks.com,2005:Question/4455682019-02-18T13:29:59Z2019-02-18T13:29:59Zlicence on virtual machineHello everybody,
I will use matlab for an industrial project that will be installed on a virtual machine.
Before deploying the server we will do some test on a different machine (and maybe different VM) in order to validate the model.
My question is can we do that with only one licence using it for the test and then in production.
BR Romain CAILLIEREhttps://kr.mathworks.com/matlabcentral/profile/authors/12702116-romain-caillieretag:kr.mathworks.com,2005:Question/4455562019-02-18T11:57:50Z2019-02-18T13:28:56ZCenter text on screenVery basic question, but how can I (exactly) center text on screen (or figure window)?
If I just use
text(.5,.5,'x'); axis off
the x is not centered on screen.Tobias Johanssonhttps://kr.mathworks.com/matlabcentral/profile/authors/4299594-tobias-johanssontag:kr.mathworks.com,2005:Question/4455672019-02-18T13:28:14Z2019-02-18T13:28:14ZLooping for calculate parameterHi MATLAB community,
I am trying create a structure to calculate a parameter,
For made this, I would to calculate de a(1)*F(:,1)+a(2)*F(:,2)+a3*F(:,3)......until a(i)*F(i), respectily until that total number of parameters ((i=number of factors), 4 in the case). I have a doubt if I use for or while for this structure.
Could you help me?
Thank you very much
Guilherme Lopes de Campos
correlation=corrcoef(X); % size X(324,19)
eigvalue = eig(correlation);
factor = nnz(eigvalue>=1);% number of factor ( 4 in the case)
nonfactor = nnz(eigvalue<1);
sumeigvalue = sum(eigvalue);
eigvalue = eig(correlation);
[n,j] = size(eigvalue)
for i = 1:n
if eigvalue(i)>=1;
a(i)= eigvalue(i); %obtained the vector of a(i)
end
end
a = sort(a,'descend')
for i=1:factor
parameter = a(i)*F(:,i); % F is a matrix (324,4)
end
Guilherme Guilherme Lopes de Camposhttps://kr.mathworks.com/matlabcentral/profile/authors/8623554-guilherme-lopes-de-campostag:kr.mathworks.com,2005:Question/4455662019-02-18T13:27:07Z2019-02-18T13:27:07ZWhy face selection won't work, when geometry of a file from STL is imported to simscape?I have been trying asssign a coordinate frames to my object in simscape. But, I can't select a face instead it will select the whole body for you, which is uncomfortable while assigining the frames. Is there a way to handle this?Shravista Kashyaphttps://kr.mathworks.com/matlabcentral/profile/authors/9714324-shravista-kashyaptag:kr.mathworks.com,2005:Question/4455522019-02-18T11:20:18Z2019-02-18T13:23:33ZHow to make the "for" loop read from a file?Hi,
The following code works well. However, I need to make it read for "s" array from each column in the attached file. The attached file (named: "result_40) has 40 columns and 10 rows. Hence, the code needs to read each column every time.
Each column reading needs to have the output files in the form of 1 to 10 (number of rows) and saved in a separate folder (lets call them V1, V2, ..., V40).
Can anyone please help me with this?
The code:
c=[0 0 0 0 0];
s=[1 2 3 4 5];
t=[0 0 0 0 0];
for j = 1:400
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);
endIsmail Qeshtahttps://kr.mathworks.com/matlabcentral/profile/authors/10292327-ismail-qeshtatag:kr.mathworks.com,2005:Question/2243122015-06-17T20:23:24Z2019-02-18T13:21:40ZMatlab unfolds folded code when I leave an open for/if loop (temporarily omit the "end" while working)I recently updated to Matlab 2015a, coming from a late 2013 or early 2014 build. I have noticed one disruptive change in particular. When I write code, I will often fold previous segments when finished, with some comment to explain what the fold contains. I will then continue writing code in later sections.
I have noticed that now when I continue working on later parts, if I make a new statement that requires an "end", such as a for loop or if statement, Matlab will automatically unfold previously folded for loops and if statements if I type much code without adding the "end." For example:
for fold = 1
z = 2;
end
for i = 1:10
disp(i);
If I fold the first for loop and keep working on code inside the second for loop without appending an "end," after a line or two of new code Matlab automatically unfolds the first for loop. Please let me know if this isn't clear. I have tried searching for some setting that governs this behavior, but have not found anything, and don't know what this sort of automatic behavior by Matlab would even be called!
Edit: I checked again, and it also does this automatic unfolding if I do something like leave a bracket open. Typing:
[1,2,3,4,5,
will unfold any closed/folded for loops or if statements in my script.
Matt Khttps://kr.mathworks.com/matlabcentral/profile/authors/1914820-matt-ktag:kr.mathworks.com,2005:Question/4455652019-02-18T13:21:19Z2019-02-18T13:21:19ZResidual modulation when sampling by a non integer multiple of the central frequencyHello all,
I'm having trouble with a "residual modulation" that appears after generating a cosine wave with matlab in which the sampling frequency is not an integer multiple of the central frequency. However, when making the FFT of the signal to see all the components, I only get the tone in 4097 which is the one I expected. I believe that that ripple is produced by the sampling frequency not being an integer multiple of the central frequency and thus, the samples are not always gotten at the same point of the sinusoid.
My question is: ¿Is there any way to avoid or correct this effect apart from increasing the sampling frequency or decreasing the central frequency?
fc = 4.092e3; % Central Frequency
doppler = 5000e-3; % Doppler Shift
fs = 16.368e3; % Sampling Frequency
t = 0:1/fs:1-1/fs; % Time vector
nFFT = 2^18; % Number of points for the FFT
f = linspace(-fs/2,fs/2,nFFT); % Frequency Axis
carrier = cos(2*pi*(fc+doppler)*t); % Carrier
figure, plot(carrier)
ylabel('Amplitude')
xlabel('Samples')
figure, plot(f,abs(fftshift(fft(carrier,nFFT))))
ylabel('Amplitude')
xlabel('Frequency (Hz)')
Thanks in advance
MiguelRPMhttps://kr.mathworks.com/matlabcentral/profile/authors/11878875-miguelrpmtag:kr.mathworks.com,2005:Question/4455642019-02-18T13:14:40Z2019-02-18T13:14:40ZFFT and wiener2Hi All,
Please ignore my dumbness. I have a single slice gray image. I wan to try wiener2 filter to keep the information and denoise it a bit. I tried the following code but i get the figure ifft_orig as final image instead of a bit blurred version of original image. Can some one tell me what am i doing wrong?
tmp = load('Slc1.mat'); % figure (orig_img.png) corresponds to this variable
tmp1 = fft2(tmp);
tmp2 = fftshift(log(1+abs(tmp1))); % figure (fft_orig.png) corresponds to this variable
[tmp4,noise] = wiener2(tmp2); % figure (filtered_fft_orig.png)
% figure (fft_orig - filtered _fft_orig.png)
tmp4 = ifftshift(tmp4);
tmp4 = ifft2(tmp4); % figure(ifft_orig.png)
roni zidanehttps://kr.mathworks.com/matlabcentral/profile/authors/12762423-roni-zidanetag:kr.mathworks.com,2005:Question/4452672019-02-16T06:45:13Z2019-02-18T13:14:15ZHi..Is there any way to open .MAX extension file in matlab. please help me to open .MAX extension files. shrisha tvhttps://kr.mathworks.com/matlabcentral/profile/authors/11347312-shrisha-tvtag:kr.mathworks.com,2005:Question/4455612019-02-18T12:51:57Z2019-02-18T13:11:44ZDear sir i am not able to use my matlab institute accound. Please helpI am getting the following error....previously I had diffrent laptop now I own this one...now I just can not open matlab.SUPRIYO BANERJEEhttps://kr.mathworks.com/matlabcentral/profile/authors/13298253-supriyo-banerjeetag:kr.mathworks.com,2005:Question/4454672019-02-17T21:25:21Z2019-02-18T13:08:33ZFrequencies of special words in a textHi. I need a matlab code that reads a text file like 'test.txt' and then counts the number of occurences of special words ( like 'good' or 'computer') that I determine.
Can anyone help me? I don't want to calculate the frequency of every word in the text, just the words that I determine in the code.Jonquilhttps://kr.mathworks.com/matlabcentral/profile/authors/14805481-jonquiltag:kr.mathworks.com,2005:Question/3996952018-05-08T11:52:36Z2019-02-18T13:08:26ZCorrect samples for HDL Optimized QPSK Receiver with Captured DataI am experimenting with the HDL Optimized QPSK Receiver design (commqpskrxhdl). I am replacing the captured data input (cdfq) with the IQ output of the TX part of the 'QPSK Transmitter and Receiver' example (commqpsktxrx). The design does not seem to compensate correctly, according to the 'after timing recovery' plot.
Here is the output of the original commqpskrxhdl design
<</matlabcentral/answers/uploaded_files/116602/cdfq.png>>
And here is the output using the transmitted data from commqpsktxrx:
<</matlabcentral/answers/uploaded_files/116603/iqout.png>>
What is the reason for this inconsistency? Should I be expecting to see the same output?
Jonathan Lowehttps://kr.mathworks.com/matlabcentral/profile/authors/9732060-jonathan-lowetag:kr.mathworks.com,2005:Question/4455632019-02-18T13:07:04Z2019-02-18T13:07:04ZFind Edge Continuity in Image I have captured a fast moving event with non-uniform background illumination, shown below. As a result, the background subtraction and its subsequent thresholding (together with localcontrast and imclearborder functions) gave me a discontinuity in the pixel values (I am just interested in the outer border and use imfill to paint the inner region later). That in return affected the accuracy of the edge detection.
Therefore, I have been using those morphological operators (imopen, imclose. imdilate, imerode, bwareaopen) to correct the image prior to performing the edge detection but that has been profoundly influenced by the 'unwanted' pixels around the image (circled as red). If these 'spots' can be masked to be 0 in their pixel value, I presume the morphological operations will just be fine with what I need to proceed.
I am wondering if anyone here has a quick-fix to resolve the issue I have?
I thank you in advance,
Ahmad
Ahmad Aliashttps://kr.mathworks.com/matlabcentral/profile/authors/9332148-ahmad-aliastag:kr.mathworks.com,2005:Question/4455592019-02-18T12:16:38Z2019-02-18T13:03:58ZUpdate Matlab's font listI have a font installed which I modified and updated in the system (windows). For some reason MATLAB will not update the font and even if I delete it completely from the system fonts, Matlab will still be able to use it. My aim is to change the font in the code editor to a more specialized font (source code pro).
How does one tell Matlab to update the version of a font or the complete font list?Andreas Sprengerhttps://kr.mathworks.com/matlabcentral/profile/authors/37848-andreas-sprengertag:kr.mathworks.com,2005:Question/3623332017-10-20T12:43:29Z2019-02-18T13:03:47ZHow to import multiple csv files into one and read it from certain folder?I am a newbie in matlab programming. I have a problem in coding to import multiple csv files into one from certain folder:
myDir = uigetdir; %gets directory
myFiles = dir(fullfile(myDir,'*.csv'); %gets all csv files in struct
That is the code. But it only shows the name of csv files, not read the content of the data. Could you please help me to find the code to read all the csv files into one file?
Thank you very much for your help
Kasih Ditaningtyas Sari Pratiwihttps://kr.mathworks.com/matlabcentral/profile/authors/9154438-kasih-ditaningtyas-sari-pratiwitag:kr.mathworks.com,2005:Question/4455452019-02-18T10:45:10Z2019-02-18T13:03:14Zvertical line through all the subplotsHow to give a long vertical line throughout one particular plot that contains multiple subplots.
I do not want annotation command.
I would like to use something like
line(x,y);
however this command does not show-up over entire range of subplots. I attach a smiliar figure below.
I want to specify (x,y) with respect to one of the subplots and then get a veritcal line througout the subplots.
Megha Pandyahttps://kr.mathworks.com/matlabcentral/profile/authors/14301589-megha-pandyatag:kr.mathworks.com,2005:Question/4454702019-02-17T22:03:01Z2019-02-18T12:57:26ZSwitch to write programsUse switch to write a program to prompt the user to enter an integer between 1 to 10 then display the English word corresponding to it. You can assume that the user inputs integers between 1 to 10.
How can I modify my program hence it works for bigger numbers? (e.g. 1-100)
I now do my 1-10 in this way. Thanks a lot!!
>> number = input('Input an integer: ');
Input an integer: 3
>> switch number
case 1
disp('one');
case 2
disp('two');
case 3
disp('three');
case 4
disp('four');
case 5
disp('five');
case 6
disp('six');
case 7
disp('seven');
case 8
disp('eight');
case 9
disp('nine');
case 10
disp('ten');
otherwise
disp('Error');
endYu Ting Luhttps://kr.mathworks.com/matlabcentral/profile/authors/12181841-yu-ting-lutag:kr.mathworks.com,2005:Question/4447502019-02-13T13:07:33Z2019-02-18T12:57:08ZHow to determine time-domain amplitude from frequency domainI'm a bit stuck here, so any help is appreciated.
So I'm trying to derive the amplitude (time-domain) of a damped sine from the frequency domain. As a test case I'll be generating my damped sine so I know what the amplitude should look like. For my I application I will not be able to do so as I will be using real signals that I dont have the parameters for (I am actually deriving them!)
The only parameter I'm struggeling with is the amplitude, I got my frequency, phase and damping with less than 1% error. My original signal looks like the snippet below and note that I only have a few samples (100!).
fs = 2e6;
t = 0:(100-1);
b = -zeta*2*pi*freq/fs;
c = 2*pi*freq/fs;
x = ampl*(exp(b.*t)).*sin(c*t+phi/180*pi);
I apply a Hamming window to my signal and perform an fft. Run it through my algorithm and I get accurate parameters for Freq, Zeta and Phi (frequency, damping and phase). So you may assume that those are known. I do compute a magnitude (i.e. amplitude in frequency domain, I'll refer to it as magnitude to prevent ambiguity) however I'm unable to correlate it to the initial (time-domain) amplitude.
Given that I can reconstruct the original signal exactly with an ifft I would imagine that I could derive the time-domain amplitude, below I've provided a working example that reconstructs the input signal.
%% parameters to construct signal
fs = 2e6;
freq = 180e3;
ampl = 44;
phi = 0;
zeta = 0.12;
n_sample = 100;
t = 0:(n_sample-1);
%% construct signal
b = -zeta*2*pi*freq/fs;
c = 2*pi*freq/fs;
x = ampl*(exp(b.*t)).*sin(c*t+phi/180*pi);
x=x';
%% Apply window, zeropad and FFT
w = hamming(length(x));
y = [w.*x; zeros(28,1)];
xFFT = fft(y)/length(y);
%% Inverse FFT
w = [w; ones(28,1)];
z = ifft(xFFT.*length(y))./w;
%% Plot
figure()
hold on
plot(x)
plot(y)
plot(z)
legend('original', 'windowed', 'reverse')
Any ideas on how I can compute the initial amplitude? So in the example above, how I can find 44?pimovietchttps://kr.mathworks.com/matlabcentral/profile/authors/3874336-pimovietctag:kr.mathworks.com,2005:Question/4455622019-02-18T12:55:38Z2019-02-18T12:55:38Zhow to get the speed calculation block in simulink for arduino ?how to get the speed calculation block in simulink for arduino ?Midhun Mickelhttps://kr.mathworks.com/matlabcentral/profile/authors/14366001-midhun-mickeltag:kr.mathworks.com,2005:Question/4447942019-02-13T16:34:37Z2019-02-18T12:42:12ZHow to extrapolate to the point of intersection i have the following data :
x=[5 6 7 8 9 10 11 12 13 14 15 16 16.5 17 17.5 18 18.5 19 19.5 20 20.5 21 21.5 22 23 24 25 26 27 28 29 30]
y=[110.515 148.485 139.68 218.925 352.41 441.755 490.11 518.295 521.32 515.825 499.51 499.345 471.685 666.715 1100.35 936.625 484.64 568.875 1444.015 1859.38 1478.71 383.84 352.75 324 282.6 239.2 215.5 189.1 165.95 142.8 137.85 128.7]
i would like to find the x value for the intersection point with the x axis (y=0)
using extrapolation by an approximate function and how i show the equation of that function
zerguine nafissahttps://kr.mathworks.com/matlabcentral/profile/authors/14771535-zerguine-nafissatag:kr.mathworks.com,2005:Question/1795992015-02-21T19:58:29Z2019-02-18T12:27:31ZHow can I calculate the slope of a line given two points?I need a function which can output the slope of a 2D line given two points. Ofcourse, I could just use m = (y2-y1)/(x2-x1), however, I have a long list of points/lines which I need to find the slope of and I don't believe this would be the most efficient method.
Something similar to the pdist2(point_a, point_b) function which I've previously used to find the distance between two points would be ideal.
Thanks in advance.
Neal Younghttps://kr.mathworks.com/matlabcentral/profile/authors/6204447-neal-youngtag:kr.mathworks.com,2005:Question/4451642019-02-15T14:19:46Z2019-02-18T12:21:30Zplot integral equation coming from ode solverI have an equation that comes from ode solver :
[t1 V1] = ode15s(dV1dt, t1, y1); plot(t1, V1 ,'-b','lineWidth',2)
then I do some basic addition or subtraction on it for eg :
Aout1=(V1-1); plot(t1,Aout1,'-b','lineWidth',2);
Now I wish to integrate the output : So I tried with
final = integral (Aout1, 0, 4.2)
But I get error :
Error using integral (line 82) First input argument must be a function handle.
I tried other things as well; but I don't achieve what I wish. Although 'cumsum' works well on it just like that. STPGhttps://kr.mathworks.com/matlabcentral/profile/authors/7060482-stpg