https://fr.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions2021-05-12T05:09:20Ztag:fr.mathworks.com,2005:Question/8279952021-05-12T05:09:20Z2021-05-12T05:09:20ZExtracting index of specified date from datetime arrayLet us say that I have a datetime array which has dates that goes like these:
'2015-05-03 23:59:56'
'2015-05-03 23:59:56'
'2015-05-03 23:59:56'
'2015-05-03 23:59:56'
'2015-05-03 23:59:57'
'2015-05-03 23:59:57'
'2015-05-03 23:59:57'
'2015-05-03 23:59:57'
'2015-05-03 23:59:57'
'2015-05-03 23:59:57'
'2015-05-03 23:59:57'
'2015-05-03 23:59:57'
Now, I would like to know the indices of one certain element, say {'2015-05-03 23:59:57'}. How can I get that?
I tried with example given in https://in.mathworks.com/help/finance/datefind.html, but even for the example given there is not getting executed in my pc. It is giving an error ‘Undefined function 'datefind' for input arguments of type 'double'.’. I suspect that it may be due to not having the proper toolbox. The toolbox that I am having are:
Curve Fitting Toolbox, Parallel Computing Toolbox, Partial Differential Equation Toolbox, Signal Processing Toolbox and Symbolic Math Toolbox
Thanks in advance.
sreeraj thttps://fr.mathworks.com/matlabcentral/profile/authors/7954413tag:fr.mathworks.com,2005:Question/7817582021-03-24T03:36:33Z2021-05-12T05:03:49Zdelete data of csv file i have created a code such that data is appended to csv file every time the loop runs
but when i run the program again the new data is added with the old one
but i want to clear out the data in then csvfile before hand
what command do i use
delete('xyz.csv') deletes the whole file SINDU GOKULAPATIhttps://fr.mathworks.com/matlabcentral/profile/authors/16460274tag:fr.mathworks.com,2005:Question/8279852021-05-12T05:03:36Z2021-05-12T05:03:36ZHow do I read the strings from the xlsx file? I have read the data, but can't get the string?anonymoushttps://fr.mathworks.com/matlabcentral/profile/authors/14068730tag:fr.mathworks.com,2005:Question/8279802021-05-12T05:03:07Z2021-05-12T05:03:07Zsolving state space using ode45 Hello Everybody
I am trying to solve a state space equation using ODE45 so that I can plot my states. My equation is of the form idot=Ai +Bv, the dimensions are [4,1]=[4;4]*[4,1]=[4,4][4,1]
When I run the code, I get " errors in 'sys' " but I dont know how to fix them. I have attached a picture of my code. Please kindly assist, thank you in advance. Basetsana Sebolaohttps://fr.mathworks.com/matlabcentral/profile/authors/16030211tag:fr.mathworks.com,2005:Question/8250652021-05-08T14:23:12Z2021-05-12T04:59:42ZFunction 'fmincon' not supported for code generationHello,
im currently trying to implement nonlinear MPC in MATLAB/Simulink using the MATLAB function block.
function u_mpc = MPC(x, u_mpc, u_0, A_ineq, b_ineq, Q_mpc, R_mpc)
costfunc = @(x,u) (x)'*Q_mpc*(x) + (u_mpc)'*R_mpc*(u_mpc);
u_mpc = fmincon(costfunc, u_0, A_ineq, b_ineq);
end
The state x is provided by a plant model, the costfunction is a simple quadratic cost with weight matrices, the matrices are taken from the workspace.
Running the Simulink model results in the error: Function 'fmincon' not supported for code generation.
I'm using the 2018b version normally, tried using 2021a but got the same error.
Is there a mistake in the code or is it simply not possible to use fmincon inside a MATLAB function block?
Thanks in advance for any help.Anuschan Albrechthttps://fr.mathworks.com/matlabcentral/profile/authors/11700669tag:fr.mathworks.com,2005:Question/8229502021-05-06T09:33:48Z2021-05-12T04:58:27ZHow to fix this error “Index exceeds the number of array elements (57)” while using minboundquad function%x = randn(50,1);
%y = randn(50,1);
points=importdata('points1.txt');
x=points(:,1);
y=points(:,2);
[qx,qy] = minboundquad(x,y);
plot(x,y,'ro',qx,qy,'b-')
Error shown is
The function is working for randomly generated points but not working for my pointset.
Can someone please help me solve this? This is the function minboundquadGowtham HariHarahttps://fr.mathworks.com/matlabcentral/profile/authors/12928241tag:fr.mathworks.com,2005:Question/8279752021-05-12T04:56:14Z2021-05-12T04:56:14Zplease suggest me how to solve this problemUnable to perform assignment because the size of the left side is 1-by-273 and the size of the right side is 1-by-273-by-2.ANUJA THAKURhttps://fr.mathworks.com/matlabcentral/profile/authors/15307319tag:fr.mathworks.com,2005:Question/3551022017-09-04T09:45:02Z2021-05-12T04:55:27ZHow to draw efficiency map contour of a motor?Given vectors of Speed, Torque and Efficiency. How do I draw the contour for efficiency map of the motor in matlab? Praveen Kumarhttps://fr.mathworks.com/matlabcentral/profile/authors/3821119tag:fr.mathworks.com,2005:Question/8248502021-05-08T07:05:03Z2021-05-12T04:52:39Zspeeding up trainbr using more cpu cores or a gputrainbr is slow on my computer often taking an hour. I'm looking at ways to speed it up. I'm trying to figure out if the Parallel Toolbox would help. It seems to say it would allow me to use multiple cpu cores, but when I'm running trainbr training it already looks like it is using multiple cores. Anybody know about this?
I have a GPU available but I recall reading trainbr can't use a GPU, anybody know about this?
Thank you!Brenthttps://fr.mathworks.com/matlabcentral/profile/authors/5323111tag:fr.mathworks.com,2005:Question/8272652021-05-11T10:27:12Z2021-05-12T04:46:48ZTrying to plot a sine+sine function but not getting a smooth curveI need to plot the sum of 2 sine curves. I can successfully plot (x,y1) and plot(x,y2), they are smooth curves, however when i try to plot(x,y) where y = y1+y2 the curve comes out like this? how do i fix this i dont know what i am doing wrong? Thanks Tyler Daineshttps://fr.mathworks.com/matlabcentral/profile/authors/14937530tag:fr.mathworks.com,2005:Question/6419252020-11-09T05:00:00Z2021-05-12T04:43:26ZIs MATLAB supported on Apple Silicon Macs?Macs with an Apple silicon processor such as the Apple M1 have two ways to run applications. Applications built for Apple silicon run natively, while apps built for Intel processors run in the Rosetta 2 environment. Which method does MATLAB support? MathWorks Support Teamhttps://fr.mathworks.com/matlabcentral/profile/authors/4622813tag:fr.mathworks.com,2005:Question/8275052021-05-11T15:59:18Z2021-05-12T04:39:33ZHow to extract 6 neasrest neigbors for particlesHello everyone.
I have a text file (kindly see the attached text file) containing neighbors of particles (ranging from 1 to 64). I want to extract 6 nearest neighbors of every particle in a seperate file.
Following is the sample from the output file. Column 1 and 2 show the particle number and column 3 show the distance.
1 19 0.874004
1 41 1.130905
1 42 1.131306
1 45 0.841402
1 50 1.393870
1 52 0.961277
1 61 0.802248
1 63 1.327221
1 64 1.408026
2 16 0.819803
2 33 1.153725
2 37 0.954796
2 39 1.439849
2 42 1.419793
2 58 1.140030
2 60 0.912613
2 63 1.454144
3 6 0.843783
3 7 1.071621
3 9 1.009899
3 10 1.254684
3 13 1.108856
3 14 1.015914
3 20 0.885181
3 35 1.263609
3 45 1.356776
3 51 1.268250
4 5 1.197906
4 40 1.238262
4 49 1.131004
4 53 1.207126
4 54 0.848770
4 57 1.278407
4 59 1.398415
4 62 0.782374
4 64 0.872153
The output which I want is
1 19 0.874004
1 41 1.130905
1 42 1.131306
1 45 0.841402
1 50 1.393870
1 52 0.961277
2 16 0.819803
2 33 1.153725
2 37 0.954796
2 39 1.439849
2 42 1.419793
2 58 1.140030
3 6 0.843783
3 7 1.071621
3 9 1.009899
3 10 1.254684
3 13 1.108856
3 14 1.015914
4 5 1.197906
4 40 1.238262
4 49 1.131004
4 53 1.207126
4 54 0.848770
4 57 1.278407
Any help will be appreciated.
Thanks in advance,
AbhinavAbhinav Srivastavahttps://fr.mathworks.com/matlabcentral/profile/authors/15404659tag:fr.mathworks.com,2005:Question/8244752021-05-07T17:22:45Z2021-05-12T04:39:17ZCalculating principal component scores from principal component coefficients of the new dataHi all,
I perfomed a PCA on dataset using the function
[coeff,score,latent,~,explained,mu]=pca(TrainingSet.X);
Then I generated new shapes (in the cartesian space) using a reduced number of principal components. Now I need to the principal component scores for these new shapes, but I can't figure out how!
Based on the fact that the original centered training data can be retrieved using
centeredData= score*coeff'
I used the following statements, which did not generate relevant results.
for i= 1:newShapesNum
newShapeScore(i,:)=newShape(i,:)*pinv(coeff(:,1:shapeModesNum)'); % i is the counter of new (generated) observations.
newSvalid=newShapeScore(i,:)*coeff(:,1:shapeModesNum)';
end
UPDATE
I also tried running a pca analysis on the new instances, and requested [score] and [coeff]. The mean shape looked good but using the centeredData formula above did not regenerate the original shape! I don't understand why though..
I'd appreciate your help in finding the principal component scores for the new shapes.
Many thanks
AminAmin Kassab-Bachihttps://fr.mathworks.com/matlabcentral/profile/authors/10036297tag:fr.mathworks.com,2005:Question/2565822015-11-20T08:47:30Z2021-05-12T04:38:35ZProduce sound from 1 Hz to 1000hzHello Everyone!
How can I produce sound from 1 Hz to 1000 Hz for a duration of 20 secs? I'm using the following code for the generation of sound for 100Hz.
amp=0.5;
fs=20500; % sampling frequency
filename = 'CampbellAudio.wav';
duration=20;
freq=100; %I want the frequency here to be from 1 to 1000
values=0:1/fs:duration;
a=amp*sin(2*pi* freq*values);
sound(a)
audiowrite(filename,a,fs);
Karthik Brshttps://fr.mathworks.com/matlabcentral/profile/authors/5264173tag:fr.mathworks.com,2005:Question/8279502021-05-12T03:10:04Z2021-05-12T04:38:31ZAmount of rain and precipitation simulationHow to design and simulate the amount of rain and precipitation using matlab or simulink? Please i badly need help. this is a requirement for my school subject. i have no idea about this. Benjie Magallanohttps://fr.mathworks.com/matlabcentral/profile/authors/10815168tag:fr.mathworks.com,2005:Question/4771492019-08-22T07:54:53Z2021-05-12T04:38:30Zhow to improve detectCheckerboardPoints performancetic
[app.imgPts,~] = detectCheckerboardPoints(img);
toc
CommandWindow:
Elapsed time is 2.233638 seconds.
Elapsed time is 2.142986 seconds.
Elapsed time is 2.198445 seconds.
Elapsed time is 2.124059 seconds.
I want to at least halve the detection time so the camera stream is faster overall.
Is there a way to calculate this as a parallel process or through the GPU?
That is exactly what must be logically possible, but I can not see any approach.
Used hardware: Intel HD Graphics 5500, Intel Core i5-5300 U
I have tested it on another PC ( Geforce GTX1070,Intel Core i5) and its much faster
but for the later use of the script I can not ensure these hardware requirements.Benjamin Kuebeck-Kohlerhttps://fr.mathworks.com/matlabcentral/profile/authors/13473861tag:fr.mathworks.com,2005:Question/2285572015-07-06T07:40:42Z2021-05-12T04:24:26ZExperts of MATLAB, how did you learn? Any advice for beginner/intermediate users?The community is very helpful, yet I feel really powerless that I cannot find the appropriate way to code, nor find the problems with the codes I have written. I have read numerous books on MATLAB, mostly related with science and engineering applications.
Any advice to improve would be greatly appreciated.
Thanks.bio limhttps://fr.mathworks.com/matlabcentral/profile/authors/4500990tag:fr.mathworks.com,2005:Question/8273352021-05-11T12:28:43Z2021-05-12T04:12:58ZHow to calculate the number of outliers from a data set according to the required maximum deviation of the remaining values Dear friends,
I'm looking for a simple promgram to do the following work.
Given a dataset of N elements:{x1,x2,...,xN}. The max-min value of this dataset is larger than D. Now I'm allowed to remove K elements of the data set, so that the remaining M-K elements satisfiy max-min<D. The problem is how to calculate the minimum possible value of K.
Now I have a program by sorting the data set and then using a "while" loop to remove one by one until finding K. But this method is toooo slow when my dataset is large, for example when N is several millions.
Does anyone have a better solution? This is more like a mathmatical problem to solve.
Thanks.LEIhttps://fr.mathworks.com/matlabcentral/profile/authors/5126204tag:fr.mathworks.com,2005:Question/8226202021-05-06T01:37:07Z2021-05-12T04:10:10ZData modeling and visualizing in matlabHi,
I am looking for a document/blog/website where I can find all the data plotting and modeling functions of matlab.
Ex: Jointplot, violin plot, boxplot, etc.
Please suggest, thank you.Shravan Kalyankarhttps://fr.mathworks.com/matlabcentral/profile/authors/14411300tag:fr.mathworks.com,2005:Question/8274802021-05-11T15:24:40Z2021-05-12T04:06:41Zsymmetry x axis y axis plotting
i have a problem to plotting something i have a code but code is so complex that i didnt bring that code
i just uploaded the picture the situation that what i want it
i have a code that shows in 1 region when plotting figure shows to quarter region
but what i want it is to full region like this picture
,what i want it is to shown origin and symmetryed region at the same figure
symmetry x axis ,y axis
how can do I? what function or what command i should input?ljaseonhttps://fr.mathworks.com/matlabcentral/profile/authors/21616368tag:fr.mathworks.com,2005:Question/8279702021-05-12T03:56:54Z2021-05-12T03:58:00ZHow to plot(x,y) if x = f(y) is givenI have a complex function which I am unable to plot. I want to plot(x,y), but the function is given as follows
x = - m*C_0*(2*sigma_star.*y + (1-k)*((pi.*y).^(0.5)).*exp(y).*erfc(y.^0.5))/(1-(1-k).*((pi.*y).^(0.5)).*exp(y).*erfc(y.^0.5)));
let say range of x is [0,20].
Other required data
C_0 = 12 ;
T_l = 903 ;
m = -2.5 ;
sigma_star = 0.0666;
k = 0.0208 ;Sunil Bhttps://fr.mathworks.com/matlabcentral/profile/authors/20034698tag:fr.mathworks.com,2005:Question/8279552021-05-12T03:15:24Z2021-05-12T03:54:21ZHow to reshape a matrix (something that can't be done with reshape function)Let's say I have a matrix A:
A = [1 4 7 10; 2 5 8 11; 3 6 9 12]
A =
1 4 7 10
2 5 8 11
3 6 9 12
and B = reshape(A,6,2) will return:
B =
1 7
2 8
3 9
4 10
5 11
6 12
But I'm wondering if there is any way to rearrange this matrix into something that looks like this:
B =
1 4
2 5
3 6
7 10
8 11
9 12
I'd like to know an easier way than doing:
B = [A(:,[1 2]) ; A(:,[3 4])]
Thank you in advance!Kenta Watanabehttps://fr.mathworks.com/matlabcentral/profile/authors/16393250tag:fr.mathworks.com,2005:Question/8279652021-05-12T03:44:55Z2021-05-12T03:46:12ZSimulink terminating process costs way more time than simulation processHi everyone,
I am currently implementing a Simulink/Adams co-simulation under batch mode, which the co-simulation process would not run Adams GUI interface in oreder to save more simulating time.
However, each time the simulating process, which takes like 40 secondes, is done, it would takes another 200 seconds to terminating the simulation as the "terminating" appears at the left-bottom of the simulink interface. Why would this happen? In my view, batch mode is supposed to save more time.
More details:
I have turned off all Data Import/Export options.
Replaced all "scopes" with “terminator".
Only one "ToWorkspace" blocks.
Under bach mode, the simulating process is relatively quick and acceptable, problem is the terminating process.
Choose interactive mode, which the co-simulation process would run Adams GUI interface, although the simulating process is a bittle slow, the whole simulation process is even quicker than batch mode. In my idea, this totally make no sense.yoshimihttps://fr.mathworks.com/matlabcentral/profile/authors/19623941tag:fr.mathworks.com,2005:Question/7124032021-01-09T06:09:16Z2021-05-12T03:31:25ZHow to convert this simulink model to VHDL ?I have simulated a sinusoidal wave using the SIMULINK by using an integrator,gain and constant. I tried to convert this to VHDL but not able to do so.
This is the SIMULINK model which I simulated in SIMULINK which I got a sinusoidal output. I want to know what are the necessary changes which I have to do in order to get a VHDL code for the same?
Jerry Jacobhttps://fr.mathworks.com/matlabcentral/profile/authors/18942340tag:fr.mathworks.com,2005:Question/8278752021-05-11T23:59:25Z2021-05-12T03:27:44ZNew to Matlab, Combining DoubleI have a 15x1 double and a 1x15 double, how can i combine them to create 15x15 double?Meg Kadwellhttps://fr.mathworks.com/matlabcentral/profile/authors/22518185tag:fr.mathworks.com,2005:Question/8279602021-05-12T03:27:39Z2021-05-12T03:27:39Zsetting color scale of two datasets in the same axis in MatlabI have two datasets on the same axis. One is plotted using "contourf" and the other one is using "scatter".
The one with scatter is "filled" according to the value of the Z-value.
The two datasets have different value range. How do I set the limit separately for the two datasets?
In the plot below, it seems the colormap is set according the latest dataset being plotted.
The "contour" will be plotted in the background while the filled circle (the second dataset) will be color-coded.
BeeTiawhttps://fr.mathworks.com/matlabcentral/profile/authors/318942tag:fr.mathworks.com,2005:Question/7190852021-01-17T09:20:22Z2021-05-12T03:15:03ZUsing Matlab coder with lsqcurvefit(), can not pass optimoptions as an argument to the target functionI want to convert my function to mex using matlab coder. The function fits data to an exponential model.
function ab_fitted = my_fit_ab_1(x0, xdata, ydata)
simple_exp_func = @(x, xdata) x(1)*exp(-x(2)*xdata); % y=a*exp(-b)
Opt = optimoptions('lsqcurvefit','Algorithm','levenberg-marquardt','MaxIter', 100);
ab_fitted = lsqcurvefit(simple_exp_func, x0, xdata, ydata, [],[], Opt);
end
The script main_1.m that calls my_fit_ab_1() is as follows,
clear
a = rand();
b = rand();
xdata = rand(8,1);
ydata = a*exp(-b*xdata);
x0 = [rand, rand];
ab_fitted = my_fit_ab_1(x0, xdata, ydata);
With matlab coder App, I can easily convert my_fit_ab_1() to mex file my_fit_ab_1_mex.mexw64.
However, if I want to pass the variable Opt as an argument, i.e. my_fit_ab_2.m
function ab_fitted = my_fit_ab_2(x0, xdata, ydata, Opt)
simple_exp_func = @(x, xdata) x(1)*exp(-x(2)*xdata); % y=a*exp(-b)
ab_fitted = lsqcurvefit(simple_exp_func, x0, xdata, ydata, [],[], Opt);
end
and main_2.m
clear
a = rand();
b = rand();
xdata = rand(8,1);
ydata = a*exp(-b*xdata);
Opt = optimoptions('lsqcurvefit','Algorithm','levenberg-marquardt','MaxIter', 100);
x0 = [rand, rand];
ab_fitted = my_fit_ab_2(x0, xdata, ydata, Opt);
the coder says " The 'optim.options.Lsqcurvefit' class does not support code generation. "
Why optimoptions can be set inside the function while can not be passed as an argument?
I've attached the four files mentioned above.Xingwang Yonghttps://fr.mathworks.com/matlabcentral/profile/authors/15183348tag:fr.mathworks.com,2005:Question/8277252021-05-11T19:40:21Z2021-05-12T03:06:33ZHow to show each iteration in for loop?initialX = input('\nWhat would you like your starting x value to be?\n');
initialY = input('\nWhat would you like your starting y value to be?\n');
xo = initialX;
yo = initialY;
dydx = 0;
for j = xo:deltaxem:sizeOfGraphXPositive
xo = j;
yo = yo + (dydx .* deltaxem);
dydx = xo + yo;
plot(xo, yo, '*', 'linewidth', 4); hold on
xlim([-sizeOfGraphXPositive sizeOfGraphXPositive]);
ylim([-sizeOfGraphYPositive sizeOfGraphYPositive]);
axis equal
title("Euler's Method");
xlabel('X Values');
ylabel('Y Values');
endAntonio Hamiltonhttps://fr.mathworks.com/matlabcentral/profile/authors/19394313tag:fr.mathworks.com,2005:Question/8279452021-05-12T03:00:13Z2021-05-12T03:00:40ZHow to use bicgstabnhx = 401;
nhy = 21;
B = zeros(1,nhy);
P = zeros(nhx,nhy);
A = -16000;
dt = 0.0001;
div = ones(nhx,nhy);
% Create m square matrix
k = 100; % define how often to repeat the pattern
result = toeplitz([A repmat([1 0 0 0],1,k)]);
m = result(1:nhy,1:nhy);
for i = 1:nhx
% Create B matrix
B = (1/dt)*div(i,1:nhy);
% Calculate Pc
Pc(i,1:nhy) = bicgstab(m,B);
end
I got this error "Right hand side must be a column vector of length 21 to match the coefficient matrix." which I believe that Pc already producing a column vectorMohammad Ezzad Hamdanhttps://fr.mathworks.com/matlabcentral/profile/authors/12504065tag:fr.mathworks.com,2005:Question/8279352021-05-12T02:44:55Z2021-05-12T02:57:44ZTransparency violation error. 'save' in 'parfor' loopI am new to coding,
Here's the complete code:
Dset = 'visit3'; % visit3
Mpath = 'E:\OneDrive - IITRAM'; %dataset path
Lpath = 'E:\datasetttt\numom2b\polysomnography';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
sp1 = 'MAT files';
op1 = 'edfs'; %edfs
op2 = 'annotations-events-profusion'; %xml
Ldir = struct2cell(dir([Lpath,'\',op1,'\',Dset]));
Ldir = Ldir(1,3:end)';
sp2 = strcat(Mpath,'\',sp1,'\',Dset);
if isfolder(sp2) ==0
mkdir(sp2)
end
parfor i = 1:1903 %size(Ldir,1)
CSname = char(Ldir(i,1));
[hdr, record] = edfread(CSname); % Edf2mat
CSname = CSname(1:end-4);
y = xml2struct([CSname,'-profusion.xml'],0);
save([sp2,'\',CSname,'_rec'],'record')
save([sp2,'\',CSname,'_info'],'hdr','y')
clc
disp(i)
toc
end
I know this error comes cuz of the 'save' in 'parfor' loop
people have suggested that we have to define the save as a function
But i am having a hard time figuring it out
I'd be glad if someone helps
thank you.Giridhar sai pavan kumar Konduruhttps://fr.mathworks.com/matlabcentral/profile/authors/21953494tag:fr.mathworks.com,2005:Question/3535042017-08-21T13:08:33Z2021-05-12T02:54:13ZGive focus to an Edit FieldIn the app I'm making, I need to move the cursor to a textbox when I press a button such that it is ready for input. I tried placing
uicontrol(app.DistanceEditField)
in the callback for the button but it doesn't work because I’m using App Designer (MATLAB R2017a). Is there a similar way that would work in the App Designer?
<</matlabcentral/answers/uploaded_files/86075/EditFocus.png>>
Morten Haastruphttps://fr.mathworks.com/matlabcentral/profile/authors/6162812tag:fr.mathworks.com,2005:Question/8279402021-05-12T02:54:13Z2021-05-12T02:54:13ZHow to find the stiffness matrix in modal analysis.How do I find the stiffness matrix when I know mass matrix, natural frequencies and mode shapes? I want to find a way by using MATLAB.
Suppose I have .Missael Hernandezhttps://fr.mathworks.com/matlabcentral/profile/authors/17682507tag:fr.mathworks.com,2005:Question/4517962019-03-22T21:12:46Z2021-05-12T02:40:33Zhow to highlighting object propertyIs there any way to highlight properties in class definition. In the example below, if I select property1, the rest of the occurance of property 1 won't be highlighted. This could be useful when I have a very long class definition.
classdef TestObj < handle
properties
property1=100;
property2;
end
methods
function self = TestObj(value1)
self.property1=value1;
end
function fun2(self, value2)
self.property2=value2;
end
end
endFranklee09https://fr.mathworks.com/matlabcentral/profile/authors/14571895tag:fr.mathworks.com,2005:Question/8279302021-05-12T02:24:01Z2021-05-12T02:39:07ZSolve two simultaneous equations for a set value of yHi, I want to solve the following two equations, for a set value.
Equation 1
A=(1/x)*(2/(y+1)*(1+(y-1)/2*x^2))^((y+1)/(2*(y-1)));
Equation 2
P=(((y+1)/2*x^2)/(1+(y-1)/2*(x^2)))^(y/(y-1))*((1)/(((2*y)/(y+1))*x^2-((y-1)/(y+1))))^(1/(y-1));
y=1.4, and is always this value
Such that
A*P=1.2, with y=1.4
Need to determine the value of x, which should be 1.928 approximatelyBob Sherlandhttps://fr.mathworks.com/matlabcentral/profile/authors/12710134tag:fr.mathworks.com,2005:Question/8279052021-05-12T01:32:57Z2021-05-12T02:36:23ZHow Can I put an asterisk as superscript and letters as subscript to a letter in ylabel of matlab plot? I want to make an Italic Bold labelling in a plot's y axis label having an asterisk as the supercript and letters as subscript as shown below. What could be the syntax for this labelling.
Anjan Goswamihttps://fr.mathworks.com/matlabcentral/profile/authors/16663399tag:fr.mathworks.com,2005:Question/8278452021-05-11T22:49:32Z2021-05-12T02:33:57ZMaking heading data continuous (i.e. instead of 359 --> 0 degrees make it 359 --> 360 degrees)I have a spreadsheet containing data about a vehicle's speed and heading against time. The spreadsheet is attached. When plotting the heading of the vehicle against time, I get this plot:
As can be seen, the near-vertical lines are mostly because the vehicle's heading changes from 359 degrees to 0 degrees (and vice versa) which makes the bearing look discontinuous. How could I make it such that the vehicle heading data reads, say, 360 degrees, 361 degrees, etc? I need it as it's easier for me to then calculate through what angle a vehicle has turned.
Please let me know if you need any clarification.
To get the plot above, my code is:
A = readmatrix("20181026075227_947BE7249B00.csv");
%find initial time, since time is in UNIX millisecond format.
%column 1 is the time, column 6 is the bearing
t0 = A(1,1);
plot((A(:, 1)-t0)/1000, A(:, 6), 'LineWidth', 3)
ylabel("Heading (degrees)")
xlabel("Time from start (s)")Amritz Ansarahttps://fr.mathworks.com/matlabcentral/profile/authors/14853089tag:fr.mathworks.com,2005:Question/2429372015-09-14T04:00:00Z2021-05-12T02:32:14ZHow can I update my MATLAB Student or Home Use license to a newer version?I have previously purchased MATLAB Student or MATLAB Home Use, and the maintenance period on my license has expired so I am not eligible to download and install the latest version of MATLAB. How can I purchase an upgrade so I can access newer versions?MathWorks Support Teamhttps://fr.mathworks.com/matlabcentral/profile/authors/4622813tag:fr.mathworks.com,2005:Question/8279252021-05-12T02:23:49Z2021-05-12T02:31:39Zhow can i get an interpolation formula?hi i would like to get an interpolation formula using: spline, pchip and makima for example:
clc;clear;close all
x=[1 2 3 4 5];
v=[0 1 0 1 0];
tt=linspace(1,5);
xq=1.5;
vq1=interp1(x,v,tt,'spline');
plot(x,v,'o',tt,vq1,'r')
legend('puntos','spline','location','southeast')rodrigo pallacan acuñahttps://fr.mathworks.com/matlabcentral/profile/authors/21916920tag:fr.mathworks.com,2005:Question/8279202021-05-12T01:59:00Z2021-05-12T02:22:04ZQuestion regarding "Source Localization Using Generalized Cross Correlation" exampleDear all
I am trying to use the example of "Source Localization Using Generalized Cross Correlation" and there is a part of code that I dont understand. If I would use N=2 in the example, values of sigr1 and sigr2 (lines 46 and 47) would contain 2 coloumns.
why would it contain 2 coloumns? shouldnt we recieve only one signal for each of them?
Moreover, When I try to look at the data in workspace it shows all of them as 0 but when I plot it using polar plot it shows the signal correctly!
I am hoping to use LMS algorithm to do the TDOA measuements and to do so I would need to have the data so I can form my error function. I have tried approaches such as using "real(sigp1)" and "imag(sigp1)" but the results would still show as 0.
Any idea how to convert them back so that I can view and work withe values?
Here is the code in the example:
Source Localization Using Generalized Cross Correlation
faraz talebpourhttps://fr.mathworks.com/matlabcentral/profile/authors/15159509tag:fr.mathworks.com,2005:Question/8278352021-05-11T22:36:39Z2021-05-12T02:11:03ZNon-square FFTHello,
I wonder if one can perform a non-square DFT efficiently. Specifically, let's say I've got a grid function with N = 2 * K points, and I want to find the lower half (by frequency magnitude) of its DFT only. An obvious way would be to perform an FFT of the input grid function and then throw away the K higher frequency components. I wonder if there is a faster way to obtain the same result.
Thanks,
DmitryDmitry Medvedevhttps://fr.mathworks.com/matlabcentral/profile/authors/22518280tag:fr.mathworks.com,2005:Question/5260212020-05-17T00:29:26Z2021-05-12T02:10:58ZFinding the coordinates of a points of 2D projection in 3D volumeHi,
I already got the projection of a 3D image on the axial plane, so now, I have the 2D projection of that image. I selected some points on the 2D projection and now I want to find the location of those points on the 3D image. Does any one know how I can find the coordinates of those points?Bahareh Salafian Esfahanihttps://fr.mathworks.com/matlabcentral/profile/authors/16594240tag:fr.mathworks.com,2005:Question/8279002021-05-12T01:27:04Z2021-05-12T02:08:32ZHaving scale that changes on same axisi am trying to adjust the scale for the beginning of the x -axis so i can better see the elastic region of the graph for a stress strain curve..
The graph is attached and you can see the elastic region (straight line) is difficult to see on the graph thus I only want to change the scale for just this part of the graph.
Cheers
Ryan Baileyhttps://fr.mathworks.com/matlabcentral/profile/authors/18562825tag:fr.mathworks.com,2005:Question/8279152021-05-12T01:49:30Z2021-05-12T02:01:14ZJacobi iteration what the wrong of my code please help% jacobi Method
clc
clear
format short
A=[2.08 -1 0 0;-1 2.08 -1 0;0 -1 2.08 -1;0 0 -1 2.08];
b=[200.0 0.8 0.8 40.8];
l=tril(-A,-1);
u=triu(-A,1);
d=diag(diag(A));
tj=inv(d)*(l+u);
cj=inv(d)*b;
xj=[1;1;1];
N=5;
for i=1:N
xj=tj*xj+cj;
[i xj']
endayah zaghlolhttps://fr.mathworks.com/matlabcentral/profile/authors/21472461tag:fr.mathworks.com,2005:Question/8278202021-05-11T22:04:07Z2021-05-12T01:55:51ZPlot data from matrix longitude, latitude and variableHi!
I have the matrix, data_1 (attached), and I want to make a map from South Atlantic with coast lines. The matrix is longitude, latitude and the variable as columns. Each lat and lon represent positions where is data, but I would like to have an interpolation.
Thanks!Pepe Grillohttps://fr.mathworks.com/matlabcentral/profile/authors/18618946tag:fr.mathworks.com,2005:Question/8278852021-05-12T00:07:45Z2021-05-12T01:54:01ZHow do I reshape a vector into a zero-diagonal matrix?I have these vectors:
x=[1;2;3;4;5;6;7;8;9;10;11;12]
y=[1;2;3;4;5;6]
How do I reshape these vectors into:
A =
[ 0 1 2 3
4 0 5 6
7 8 0 9
10 11 12 0]
B=
[0 1 2
3 0 4
5 6 0]
Dan Ibarrahttps://fr.mathworks.com/matlabcentral/profile/authors/22354251tag:fr.mathworks.com,2005:Question/8276002021-05-11T17:57:43Z2021-05-12T01:53:03ZHow to do code with 2 equations with 2 unknowns and an angle that goes from 0 to 360?A sin x - B sin y + Csin z = 0
B cos y - C cos z - A cos x + H= 0
A, B, C, & H are known values.
z : it is going full rev (0 to 360 degrees)
I want to find y and x.AMJAD ALMAYAHIhttps://fr.mathworks.com/matlabcentral/profile/authors/19868471tag:fr.mathworks.com,2005:Question/8279102021-05-12T01:48:49Z2021-05-12T01:48:49Zmatlab or simulink generate a stream data by framehi! i am new to matlab. now i need to generate a series of stream data . my data size is so big (over 100GB for 10s) so that i can't store that in my memory. so i want create them real time and frame by frame (such as 10000frames ,luckly all the my frame is very similar ). because of same sample rate, all of my frame have a same length. but i don't know which function can solve the problem. and now i just generate about 1s data in memory and the send it out by sumulink.
peng dahuihttps://fr.mathworks.com/matlabcentral/profile/authors/20820348tag:fr.mathworks.com,2005:Question/8278952021-05-12T00:51:41Z2021-05-12T01:47:39ZHow to convert multiple numbers in NaN?Hi there, I have a matrix (8760x18) with random numbers. the values have valid zeros and invalid zeros. The invalid zeros are continually presented, I mean postion (12 13 14 15 16 . . . 21) or any position between 1 and 8760. The valid zeros have randomly positions, I mean position (9 has zero value) but the position before and after are numbers > 0. To understand better I did an example, which is varaible (y). It has 10 continually invalid zeros that I would like become NaN, but it has also valid zeros that I would like to keep. My idea is the next -> Keeping a conditional that says, if in my position (i) + five following positions, it is equal to zero, and my position (i) - five previous positions, is equal to zero, leave the value of NaN.
|-- invalid zeros--| |valid|
y= [1 2 3 5 2 6 4 8 0 5 2 0 0 0 0 0 0 0 0 0 0 1 2 5 6 9 8 74 0 0 0 32 8 4 6 1 10 2]';
I already try to do the next code, but the result is:
for i=1:length(y)
if y((i)+5,1)==0 & y((i)+4,1)==0 & y((i)+3,1)==0 & y((i)+2,1)==0 & y((i)+1,1)==0
y(i,1) = NaN;
end
end
y= [1 2 3 5 2 6 4 8 0 5 NaN NaN NaN NaN NaN NaN NaN 0 0 0 0 0 2 5 6 9 8 74 0 0 0 32 8 0 6 1 10 0];
And like the last number is zero, obviusly get an error that exceeds array bounds, but coudn't fix it.
Index in position 1 exceeds array bounds (must not exceed 38).
Error in analise_dados_mp25 (line 71)
if y((i)+5,1)==0 & y((i)+4,1)==0 & y((i)+3,1)==0 & y((i)+2,1)==0 & y((i)+1,1)==0
Thanks in advanced.Fabian Morenohttps://fr.mathworks.com/matlabcentral/profile/authors/18939934tag:fr.mathworks.com,2005:Question/3188322017-01-02T22:08:23Z2021-05-12T01:39:09ZI need code for image encryption using Rc4 Please I need code of RC4 to image encryption ..
Thanks.noor al ebadihttps://fr.mathworks.com/matlabcentral/profile/authors/8976970tag:fr.mathworks.com,2005:Question/8072922021-04-20T08:28:29Z2021-05-12T01:20:01ZHow to read specific lines from a text file and store them in a matrix?Hello everyone,
I want to create a matrix from the attached text file that only includes the lines after the one that reads "#begindata". Basically, I want a matrix that includes the headers of the columns and all the numeric data from the file, but none of the information preceding it.
Also, would it be possible to use the same code when reading information from a file with a different number or rows and columns?
Thank you!Remember Samuhttps://fr.mathworks.com/matlabcentral/profile/authors/22265979