https://kr.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — 새 질문2021-05-13T18:39:39Ztag:kr.mathworks.com,2005:Question/8291982021-05-13T14:30:57Z2021-05-13T18:39:39ZSimulink Scope doesn't open at allI'm new to MATLAB and I've been trying to simulate a simple RC circuit response over time with the scope on Simulink, but it refuses to open.
When I click on the scope (and I've tried the floating scope as well) the popup window appears in the task manager and in the opened apps list but when I click on it nothing happens. There was one time an error message showed up but just like the scope I couldn't even read it because it refused to open - at this occasion the main MATLAB page also died and just gave Windows error sounds when I clicked on it.
I am using a just installed R2015a MATLAB with a license provided by the university I study in, on a fresh installation of Windows 10. Maybe I forgot to add something on installation?
Edit 1: I found out that I can't open figures or plots either. I believe the problem is more widespread than I originally thought.
Edit 2: I gave up trying, had lunch and after about two hours I tried again. Lo and behold, it just worked!(?) Didn't change anything and it just poped back to life. Now I want to know why this happened...
Here is an image of the problem:Julio Calandrinhttps://kr.mathworks.com/matlabcentral/profile/authors/22526459tag:kr.mathworks.com,2005:Question/8294032021-05-13T18:02:16Z2021-05-13T18:37:14ZODE 45 solution copying initial conditionI am trying to solve second order ODE equation:
Mx'' = -Kx (where M and K are mass and stiffness matrices that are 300 x 300)
X0 = [x0; xdot0]; (each x0 and xdot0 are 300 x 1 vector) (X0: 600 x 1 vector)
f = @(t, x) String(t, x, M, K, N);
function dydt = String(t, X, M, K, N)
x1 = X(1:N);
x2 = X(N+1:end);
dydt1 = x2;
dydt2 = M \ (-K*x1)
% A = -K.*x1;
% A = sum(A, 2);
% dydt2 = M\A;
dydt = [dydt1
dydt2];
end
tSpan = linspace(0 100, 1000)
[~,X] = ode45(f, tSpan, X0);
Issue that I am facing is I am not sure why rows of X are filled with the initial condition X0.
Given function String and using ode45 method, shouldn't it solve the ode and fill the rows with the soltuion accordingly?
Is there any key parts that I am missing?
Ji Hwan Parkhttps://kr.mathworks.com/matlabcentral/profile/authors/21006350tag:kr.mathworks.com,2005:Question/4020562018-05-22T23:03:48Z2021-05-13T18:36:42Zurlread retrieves data but webread retrieves errorI'd like to retrieve data from a .csv generated by a website. urlread works, but is not recommended. webread returns a http error message. Anyone know what feature of webread causes different behavior than urlread? Alternatively, is there a script to just download the file (e.g. web.m but without the interactive browser)?
>> urlread('https://ssd.jpl.nasa.gov/sbdb_query.cgi?com_orbit_class=JFC;table_format=CSV;c_fields=AbAc;&query=1')
ans =
'spkid,full_name
1000099," 8P/Tuttle"
1000061," 96P/Machholz 1"
1000047," 126P/IRAS"
1000154," 262P/McNaught-Russell"
1003435," 333P/LINEAR"
1002585," 342P/SOHO"
1001439," P/1999 J6 (SOHO)"
1001843," C/2002 R5 (SOHO)"
1001852," P/2002 S7 (SOHO)"
1002413," P/2006 R1 (Siding Spring)"
1003317," P/2008 Y12 (SOHO)"
1003064," P/2010 D2 (WISE)"
1003231," P/2013 AL76 (Catalina)"
1003377," C/2015 D1 (SOHO)"
'
>> webread('https://ssd.jpl.nasa.gov/sbdb_query.cgi?com_orbit_class=JFC;table_format=CSV;c_fields=AbAc;&query=1')
ans =
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
<head>
<title>ERROR</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body bgcolor="#FFFFFF" link="#FF0000" vlink="#0000FF">
<h2>Error Condition</h2>
</body>
</html>
Damon Landauhttps://kr.mathworks.com/matlabcentral/profile/authors/3208804tag:kr.mathworks.com,2005:Question/8267802021-05-10T19:09:27Z2021-05-13T18:33:02ZI need to create a 3d plot with each step of fminsearchHi, here is my program
par0 = [0.005276, 0.5017, 88.6357];% initial values
fun_objetivo = @(par,pfrac)FunObjetivo(par);
options = optimset('MaxFunEvals',3000,'Display','iter','PlotFcns',@optimplotfval);
%We use here the Nelder-Mead method
par_optimos = fminsearch(fun_objetivo, par0, options);
I need help with some comands to create a 3d plot, what I want is a 3d plot with "par_optimos(1)" as X, "par_optimos(2)" as Y and "min f(x)" as Z , so I can see how two of the values of my vector "par_optimos" are optimized in each iteration.
Jorge Armando Vazquezhttps://kr.mathworks.com/matlabcentral/profile/authors/21931471tag:kr.mathworks.com,2005:Question/8291832021-05-13T13:59:33Z2021-05-13T18:30:14ZHow to remove outlier of time series signal data by using cubic spline interpolation?Hello everybody am new for Matlab and need an algorithm for my project that computes the following problems.
I have a time series 1D signal data like this:
x=[180 142 213 78 90 192 40 38 105 162 270 262 211 170 72 28 40 55 90 201]
and
L = numel(x),
fs=4
t=0:1/fs:(L-1)/fs;
I want to detect and remove outliers which is less than 50 and greater than 200 by using cubic spline interpolation.
Thank you so much in advance for all your contribution Yared Danielhttps://kr.mathworks.com/matlabcentral/profile/authors/22225744tag:kr.mathworks.com,2005:Question/8294232021-05-13T18:29:31Z2021-05-13T18:29:31ZRemove Figure window from appearing at all in programHi,
I (beginner in matlab) have a loop that plots multiple graphs and then saves them as png's in my code. I have looked at other answers and they mention code such as
fig1 = figure(1, 'Visible', 'off');
https://www.mathworks.com/matlabcentral/answers/399473-keep-figures-invisible-until-for-loop-is-over-to-reduce-time-duration
The loop I have eventually generates around 100 graphs for my data set. My concern is that by displaying or attempting to display each plot it unneccsarily slows down the code.
Does setting the visible to off keep it from wasting processing time generating these figures to the screen?
Ian Bunkerhttps://kr.mathworks.com/matlabcentral/profile/authors/22103789tag:kr.mathworks.com,2005:Question/8294082021-05-13T18:14:01Z2021-05-13T18:28:47ZnX2 matrix. Random instances of 0,1,2... in column 1. Need to add all corresponding values of column 2 for each of 0,1,2... and create a matrix m X 2 where 1st column is 0,1,2.. and second column is the resultant sum of previous defined content. Hi all,
I am a beginner in Matlab and most of my learnings come from kind answers to different problems in these sections.
I have a 11300 X 2 matrix which I imported from an excel file. Column 1 has 90 intsnaces of 0, 75 instances of 1, 87 instances of 2 and so on. So the number of instancs of 1,2,3….190 is random. For example:
0 0.16
0 0.23
. .
. .
1 9.34
1 0.34
. .
. .
190 4.5
Each instances has certain corresponding values in the column. I am looking to add up all the values of corresponding value of column 2 so that I can have the 191 X2 matrix looking as following:
0 2.7 % (ex:2.7 = 0.16 + 0.23 +.. all other values in second column corresponding to 0)%from above example
1 15.5 % (ex:15.5 = 9.34 + 0.34 +.. all other values in second column corresponding to 1)%from above example
2 0.6 % and so on as above
. .
190 9.8
Is there anyway I can get some help?
Tanmoy Sarkarhttps://kr.mathworks.com/matlabcentral/profile/authors/17159964tag:kr.mathworks.com,2005:Question/8294182021-05-13T18:26:45Z2021-05-13T18:26:45ZProblem with Color KeyingGood Morning,
I have come here because I have a problem with my task.My mission is to count Center of Gravity (CoG) but first i had to recorded video of my object (small ball) and now I would like to use color keying to get orientation of small ball (coordinates). I have no any ideas how to do that.
Thank you in advance!Dawid Jakielhttps://kr.mathworks.com/matlabcentral/profile/authors/12937751tag:kr.mathworks.com,2005:Question/8293882021-05-13T17:44:01Z2021-05-13T18:25:59Zsending array of float data through serial portHi,
I'm trying to send an array of float data through serial port using the function write(device,data,datatype), I put in datatype "double" or "single" but I have this error "Expected input number 2, count, to be integer-valued." How can I send float data ? omar mouknihttps://kr.mathworks.com/matlabcentral/profile/authors/20347027tag:kr.mathworks.com,2005:Question/8294132021-05-13T18:24:57Z2021-05-13T18:24:57Zhow to make the x y axis scale
Hi:
Does anyone knows how to make such a figuer in Matlab, the X ,Y axis were not shown, but there were scales indicating the X, Y axis messages!
thanks!
Hang Zenghttps://kr.mathworks.com/matlabcentral/profile/authors/15673046tag:kr.mathworks.com,2005:Question/8293982021-05-13T18:01:38Z2021-05-13T18:22:14ZIndex exceeds the number of array elements (2)I am doing homework for school where i have to get a spring oscillation graph. The program keeps reporting an error to me and I don’t know what could be wrong.
function [t,Y]=naloga6
g=9.8;
m=1;
k1=20;
k2=30;
tr=0.4;
L=2;
alfa=pi/6;
tstart=0;
tfinal=10;
y0 = [L*cos(alfa);L*sin(alfa)];
[t,Y] = ode23(@desne_strani, [tstart tfinal],y0,[],g,m,k1,k2,alfa,tr);
figure(16);
% hold on
% plot3(Y(:,1),Y(:,2),Y(:,3),'r')
dimen= [min(Y(:,1)) max(Y(:,1)) min(Y(:,2)) max(Y(:,2))+0.5 ];
casi=tstart:0.01:tfinal;
Yfilm=interp1(t,Y,casi);
for i=1:size(casi,2)
plot(Yfilm(i,1),Yfilm(i,2),'ro')
axis(dimen)
Film(i)=getframe;
end
function dydt = desne_strani(t,y,g,m,k1,k2,alfa,tr)
dydt = [
y(4)
0
y(6)
-((k1*y(1)*cos(alfa))/m)-((k2*y(1)*cos(alfa))/m)-(tr*g*cos(alfa))
0
-((k1*y(3)*sin(alfa))/m)-((k2*y(3)*sin(alfa))/m)-(tr*g*sin(alfa))
];
------------------------------------------------------
Errors:
Error in naloga6>desne_strani (line 35)
y(4)
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode23 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in naloga6 (line 15)
[t,Y] = ode23(@desne_strani, [tstart tfinal],y0,[],g,m,k1,k2,alfa,tr);Nejc Jansahttps://kr.mathworks.com/matlabcentral/profile/authors/21958604tag:kr.mathworks.com,2005:Question/8284652021-05-12T15:27:24Z2021-05-13T18:21:01ZQuiver with color: Add-onSadly Matlab didn't enabled color-coded vectors in their ever so neat function quiver
Therefore there are endless detours open in Matlab, like the one I found for plotting what I think of:
https://de.mathworks.com/matlabcentral/fileexchange/17582-ncquiverref
It's promissing
"all vectors have the same size based on the optimum value for the grid provided"
Given that I don't understand the function itself I can't work out how . My best try is:
[x,y] = meshgrid(-2:0.2:2);
xr = -y;
yr = x;
ncquiverref(x,y,xr,yr,'col')
What's looking pretty pretty (I mean, look at that clean arrows), but monochrome.
Niklas Kurzhttps://kr.mathworks.com/matlabcentral/profile/authors/18516014tag:kr.mathworks.com,2005:Question/8291732021-05-13T13:31:26Z2021-05-13T18:16:52ZInverse fourier transform is not regenerating original signal amplitudes Hi,
I have a 50 Hz high-sampled signal with 3300 Hz noise and I'm trying to use a simple and manually designed low-pass filter to remove the noise and create the pure 50 Hz signal. When I plot the pure signal after using the ifft, the amplitudes are not correct, however the noise removal seems to work. Anybody who knows what I am missing? My code is shown below:
fs = 1/0.00001; % sample rate
fsdur = 0.00001; % sample duration
freqs = linspace(0, fs/2+1, fs/2);
data=Var1(1:fs) % 1 second of data
sigfourier=fft(data)/fs
ampsigfourier=sqrt(real(sigfourier).^2+imag(sigfourier).^2)*2 % check amplitudes
PSD=sigfourier.*conj(sigfourier)*fs
% simple filter
vec=zeros(round(fs),1);
positions=[10:60];
vec(positions)=1;
newfourier=sigfourier.*vec
signalfiltered=real(ifft(newfourier))
Sebastian Engelsgaardhttps://kr.mathworks.com/matlabcentral/profile/authors/19409979tag:kr.mathworks.com,2005:Question/8293082021-05-13T16:52:23Z2021-05-13T18:14:36ZSolutions are only valid under certain conditionsHi,
I am trying to solve for g in terms of y and z and I believe the solve command should give me four roots in terms of y and z.
But the warning says
Warning: Solutions are only valid under certain conditions. To include parameters and conditions in the solution, specify the 'ReturnConditions' value as 'true'.
I tried to use 'ReturnConditions' value as 'true' but didn't work out.
Can someone please help me, shouldn't be a big issue I guess in the above problem?
My code is
%solving fourth order algebraic equation to get g
syms x n g y z
x = 0.0585;
n = 0;
solve(1/g-sqrt(1 + z.^2/((2*n+1)*pi*y + 4.4*pi*x*g).^2) == 0, g);
gTikuhttps://kr.mathworks.com/matlabcentral/profile/authors/21915524tag:kr.mathworks.com,2005:Question/8293482021-05-13T17:15:38Z2021-05-13T18:12:14ZPlotting leaving empty space before line begins
So this plot has a gap before the beginning of the line. I have checked the arrays being inputted and they have the correct values and therefore there should be no gap.
My current theory is based on the bottom and that when the program plots the points it is rounding the axis numbers and therefore not centering the graph at the start of the line.
Any ideas on how to fix this?Ian Bunkerhttps://kr.mathworks.com/matlabcentral/profile/authors/22103789tag:kr.mathworks.com,2005:Question/8293832021-05-13T17:42:49Z2021-05-13T18:11:30ZI'm getting an error and don't know how to fix it.So I'm averaging a bunch of data and instead of opening up all the files manually and such, I'm using a for loop. Here's what my code looks like.
close all;
clc;
for k=1:10
filename=sprintf('20.5in_%d.bin',k);
fid=fopen('filename','r');
data=fread(fid,[1,Inf],'single');
sum=sum+data;
end
Average=sum/10;
plot(data/max(data));
plot(Average/max(Average));
close all
However, I get this error when I try to run it.
Error using fread
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in in205 (line 6)
data=fread(fid,[1,Inf],'single');
I'm not sure what the problem is or how to fix it. If I don't use a loop it works so any help would be greatly appreciated!!!
close all;
clc;
fid=fopen('20.5in_1.bin','r');
data=fread(fid,[1,Inf],'single');
plot(data/max(data));
close all
^the code that works without the loopRebekah Higginshttps://kr.mathworks.com/matlabcentral/profile/authors/17452108tag:kr.mathworks.com,2005:Question/8244802021-05-07T17:29:26Z2021-05-13T18:08:19ZIncreasing the number of iterations in GeneralizedLinearModel.fitDear Experts,
I am fitting a matrix of predictors (desmat) to a timeseries (ts) and to do it I use a GeneralizedLinearModel object as follows:
m = GeneralizedLinearModel.fit(desmat, ts);
However, I often get the following warning:
Warning: Iteration limit reached.
> In glmfit (line 332)
In GeneralizedLinearModel/postFit (line 605)
In classreg.regr.FitObject/doFit (line 95)
In GeneralizedLinearModel.fit (line 887)
I have to use GeneralizedLinearModel.fit instead of glmfit because I am also running some contrasts between the model parameters down the line.
My question is this: how can I increase the number of maximum iterations in this fit method, so I can try to make my model converge? Alternatively, is there a way to do a contrast of coefficients that returns p-values using the glmfit function?
Thank you very much,
Leonardo TozziLeonardo Tozzihttps://kr.mathworks.com/matlabcentral/profile/authors/12009518tag:kr.mathworks.com,2005:Question/4757902019-08-12T08:37:28Z2021-05-13T18:04:31ZApp Designer 2019b : automatic add of Figbrowser menu at load of app and then it's impossible to save or runI create a new blank app in App designer 2019b and save it immediately without editing anything. Then I reopen it and a complex FigBrowser menu appears. I am now unable to either run the app or save it. both buttons are greyed out. Any idea how to fix that? All my older apps have become impossible to edit and save.Florentin Coppeyhttps://kr.mathworks.com/matlabcentral/profile/authors/8839602tag:kr.mathworks.com,2005:Question/8292932021-05-13T16:42:01Z2021-05-13T18:01:59ZHow to reconstruct a matrix?i have
x = [8, 9, -3, 9, 5, -4, -1, 3, 10, 10]
y = [-6; 4; 4; -2; 2]
z = diag(y)
how can i reconstruct matrix z into this look?
z =
-6 0 0 0 0 8
0 4 0 0 0 9
0 0 4 0 0 -3
0 0 0 -2 0 9
0 0 0 0 2 5
8 9 -3 9 5 -4
is there other way than this?
z = [-6 0 0 0 0 8; 0 4 0 0 0 9; 0 0 4 0 0 -3; 0 0 0 -2 0 9; 0 0 0 0 2 5; 8 9 -3 9 5 -4]
Hearthy Tampolhttps://kr.mathworks.com/matlabcentral/profile/authors/17284876tag:kr.mathworks.com,2005:Question/8292882021-05-13T16:32:39Z2021-05-13T17:59:27ZHow to evaluate a function that has been saved to a variableI have a function:
f = @(x) 2*tanh(x/2)
I'm taking the 1,2,3 derivatives of
d1 = diff(f(x))
d2 = diff(f(x),2)
d3 = diff(f(x),3)
I want to plot them now but not sure how to do this. If I try the following it gives me an error:
x = -1:0.01:1;
plot(x, d1(x))
How do you plot them if they are stored in a variable? or evaluate them?Ethhttps://kr.mathworks.com/matlabcentral/profile/authors/14439759tag:kr.mathworks.com,2005:Question/8293682021-05-13T17:31:25Z2021-05-13T17:58:32Zpad matrix to a particular sizeI have matrix M of size m x n
m and n may or may not be equal - M can be rectangular or square matrix - where m and n are less than 150,
I wanted to resize M to 150 x 150 by padding border with zeros, such that the m x n will come in the center
M_resized = padarray(M,[x y],0,'both');
how to compute value for x and y such that i can use the same line of code for any matrix,
or is there any another way to do?Elysi Cochinhttps://kr.mathworks.com/matlabcentral/profile/authors/3625227tag:kr.mathworks.com,2005:Question/8290382021-05-13T08:21:29Z2021-05-13T17:58:27ZHow can I optimize initial guess of a solution? Hi, I solved a system of non linear ODEs with bvp4c.
The system is a bit complicated, since it contains 17 equations with 17 variables.
I realized that initial guess strongly influences the final solution, which is normal.
I tried to enter optimal values of my variables as initial guess, giving them the order of magnitude I expect during simulation.
In this way, the maximum residual has decreased a lot, however it seems still high.
I have the following warning:
... The maximum residual is 0.16, while requested accuracy is 0.001
How can I further decrease the residue? Is there available an optimizer of initial guess?
Thank you!
Elia Painihttps://kr.mathworks.com/matlabcentral/profile/authors/7115132tag:kr.mathworks.com,2005:Question/8293432021-05-13T17:14:15Z2021-05-13T17:55:29ZGetting Input Error With CodeI am trying to run the following code and keep running into the error: Not enough input arguments. Not sure what the issue is?
This is the code:
function [targlinear] = targlin(n)
targlinear = zeros(n,n);
for i = 1:n-1
for j = (i+1):n
targlinear(i,j) = abs(i-j);
targlinear(j,i) = targlinear(i,j);
end
end
DissMale = abs(.50 - Crime_Male);
DissFemale = abs(.50 - Crime_Female);
[R,C] = size(DissMale);
[R,C] = size(DissFemale);
[outperm, rawindex, allperms, index, coord, diff] = ...
uniscalqa(DissMale, targlin(R), randperm(R), 2);
uniscalqa(DissFemale, targlin(R), randperm(R), 2);
coord
outperm
figure;
[linearlength] = linearplot(coord,ouztperm);Bri Menhttps://kr.mathworks.com/matlabcentral/profile/authors/22539745tag:kr.mathworks.com,2005:Question/7580942021-02-27T18:27:34Z2021-05-13T17:51:21ZPassing Covariance Matrix in Likelihood MaximizationI've a question about code design for a numerical optimization of the likelihood function of the sort:
LL = LogLik(x,y,Param,L,Ps,P)
My objective function makes use of the multivariate normal probability density in the following fashion:
eta = mvnpdf(y,x*Phi,Sigma);
Where sigma is passed throug the parameter vector 'Param' (together with Phi). I then try to numerically optimize that through fmincon but then Sigma shoud be a positive-definite covariance matrix, condition that is not always defined and causes an error.
Results = fmincon(@(Param)LogLik(X,Y1,Param,L,Ps,P),x0,[],[],Aeq',beq,[],[],[],options)
I'm asking your help as I suspect this is not the right approach to solve the problem at hand.Marco Lagohttps://kr.mathworks.com/matlabcentral/profile/authors/16289568tag:kr.mathworks.com,2005:Question/8284452021-05-12T15:10:10Z2021-05-13T17:48:53ZHow to add .stl file to a robot?Hi! I would like to add an .stl file to a robot link created with the robotic toolbox. I checked the Visuals field of the body and the model has been loaded properly, but when I use show(robot) nothing happens. How can I fix it?
%body1
body1 = rigidBody('body1');
addVisual(body1, "Mesh", 'IRB 910SC_IRC5C_Arm1_450_rev0.STL');Valeria Letohttps://kr.mathworks.com/matlabcentral/profile/authors/10598907tag:kr.mathworks.com,2005:Question/8284152021-05-12T14:26:50Z2021-05-13T17:47:38ZEfficient assigning of class properties - on multiple levelsHey everyone,
I have the following problem: I got a custom class A that has a property b which is an array of objects of class B. Now each of these objects of class B has a property that is a matrix, let's call it C. I often have to set specific columns of C - many of them, to the same vector. For example, I calculate the vector [1;0;0]. Now, I have to write this vector to, for example, A.b(2).C(:,3), A.b(17).C(:,2), A.b(20).C(:,4) etc. (let's say to 10 places). Right now, I'm doing this via a for-loop.
This works like a charm, but as the b-arrays become bigger (say 1000 items long), this type of operation becomes the dominant factor for the runtime. Writing the vector to all places where it is required takes much longer than actually calculating the vector. (the calculation is quite simple though)
In another place in my code, I was able to get the runtime down significantly by using deal(). I got 2 questions:
- Could I speed up that task by an appropriate use of deal()?
- If yes, how do I do that?
I was trying something like [A.b(vecA).C(:,vecB)] = deal(v) where vecA and vecB contain indices and v is the calculated vector, but apparently using index-vectors on two levels is not OK for MATLAB.
Thanks in advance,
AndreasAndreas Walkerhttps://kr.mathworks.com/matlabcentral/profile/authors/5648767tag:kr.mathworks.com,2005:Question/8293932021-05-13T17:44:47Z2021-05-13T17:47:20ZStandalone app compiled with MCR 9.5 doesn't display plots properly on several computersI compiled a standalone app with MCR 9.5/Matlab R2018b on my Windows 7 computer (with NVIDIA Geforce and Intel Core i7). It worked as expected on my computer.
However, when my co-worker tested it on their own set-up (Windows 10, AMD Radeon R3, AMD Ryzon 5), some plots did not display properly, as shown in the next pictures. Even when we tried recompling it on their computer using the same Matlab version, the problem remained.
Is this a known issue? Is there any way of fixing it?
Faulty output (Windows 10, AMD Radeon R3, AMD Ryzon 5):
Correct output (Windows 7, NVIDIA Geforce, Intel Core i7):
Juliette Martihttps://kr.mathworks.com/matlabcentral/profile/authors/7206723tag:kr.mathworks.com,2005:Question/8233802021-05-06T16:05:25Z2021-05-13T17:39:48ZHow to pretrain a stochastic actor network for PPO training?I want to create a stochastic actor network that outputs an action array of 10 values between 0 and 1 given an observation array of 28 normalized values. I specified upper and lower limits as follows to ensure the actor's output to be between 0 and 1:
ActionInfo = rlNumericSpec([numActions 1],'LowerLimit',[0;0;0;0;0;0;0;0;0;0],'UpperLimit',[1;1;1;1;1;1;1;1;1;1]);
My stochastic network looks as follows:
I have created a normalized training data set (input dimension 28, target dimension 10). How do I use this data set to pretrain above network?
Clarification: I want to train the network before starting the PPO agent training.Jan Dewezhttps://kr.mathworks.com/matlabcentral/profile/authors/21651930tag:kr.mathworks.com,2005:Question/8293782021-05-13T17:38:56Z2021-05-13T17:38:56ZDeblurred image quality assesmentHi,
Is there any non reference quality metric for deblurred images?
ie. We have a blurred image of a real scene. We do not have its ground truth of sharp image. We deblurred it. So, is there any quantitative analysis method to find the deblurred image quality without using a reference?Nisha Varghesehttps://kr.mathworks.com/matlabcentral/profile/authors/15909726tag:kr.mathworks.com,2005:Question/8293732021-05-13T17:38:10Z2021-05-13T17:38:10ZError: Failed to initialize the interactive sessionI am trying to validate a cluster profile. I was able to do all tests but the parallel pool test. I have attached my validation report below. Any help is appreciated.
VALIDATION REPORT
Profile: beoshock
Scheduler Type: Generic
Stage: Cluster connection test (parcluster)
Status: Passed
Start Time: Thu May 13 12:21:31 CDT 2021
Finish Time: Thu May 13 12:21:31 CDT 2021
Running Duration: 0 min 0 sec
Description:
Error Report:
Command Line Output:
Debug Log:
Stage: Job test (createJob)
Status: Passed
Start Time: Thu May 13 12:21:31 CDT 2021
Finish Time: Thu May 13 12:21:57 CDT 2021
Running Duration: 0 min 26 sec
Description:
Error Report:
Command Line Output:
Debug Log:
Stage: SPMD job test (createCommunicatingJob)
Status: Passed
Start Time: Thu May 13 12:21:59 CDT 2021
Finish Time: Thu May 13 12:22:37 CDT 2021
Running Duration: 0 min 38 sec
Description: Job ran with 2 workers.
Error Report:
Command Line Output:
Debug Log:
Stage: Pool job test (createCommunicatingJob)
Status: Passed
Start Time: Thu May 13 12:22:39 CDT 2021
Finish Time: Thu May 13 12:23:06 CDT 2021
Running Duration: 0 min 27 sec
Description: Job ran with 2 workers.
Error Report:
Command Line Output:
Debug Log:
Stage: Parallel pool test (parpool)
Status: Failed
Start Time: Thu May 13 12:23:08 CDT 2021
Finish Time: Thu May 13 12:24:41 CDT 2021
Running Duration: 1 min 33 sec
Description: Failed to initialize the interactive session.
Error Report: Failed to initialize the interactive session.
Caused by:
Error using parallel.internal.pool.AbstractInteractiveClient>iThrowIfBadParallelJobStatus (line 433)
The interactive communicating job errored with the following message: MatlabPoolPeerInstance{fLabIndex=1, fNumberOfLabs=2, fUuid=b10ec9e0-6fbc-43e5-8566-67ed5d06514d} was unable to find the host for MacBook-Pro:27370 due to a JVM UnknownHostException: null
pardhasai chadalavadahttps://kr.mathworks.com/matlabcentral/profile/authors/13877103tag:kr.mathworks.com,2005:Question/8243952021-05-07T15:46:33Z2021-05-13T17:33:11ZMatlab: Split and Plot the training data set and test data set.Hi Everyone
Thanks for any Help
i need some solution for this practice.
First, divide the data into two parts: training data (Train) and test data. Consider 30% of the data for the test set and 70% as the training set.
Second, This segmentation should be completely random without duplicate data. In other words, none of the randomly selected test set data should be present in the training set and also the data in the test set should not be duplicate. (Use efficient functions in MATLAB for this purpose)
--> Perform the regression for the polynomial degree from degree 1 to degree 100 and display the results of these 100 experiments in the plot below.
--> This example plot shows the MSE error for each degree of polynomial for both the training set and test set.
i have generated the data in one dimension using the following code :
rng(914163506);
temp=0:.15:2*pi;
x = sin(temp)+.2*randn(size(temp));arash Mohahttps://kr.mathworks.com/matlabcentral/profile/authors/22402017tag:kr.mathworks.com,2005:Question/8225552021-05-05T23:18:23Z2021-05-13T17:31:55ZMATLAB (Please Help, Full Practice in the below) : Split and plot the training data set and test data set. Hi Everyone
Thanks for any Help
i need some solution for this practice.
First, divide the data into two parts: training data (Train) and test data. Consider 30% of the data for the test set and 70% as the training set.
Second, This segmentation should be completely random without duplicate data. In other words, none of the randomly selected test set data should be present in the training set and also the data in the test set should not be duplicate. (Use efficient functions in MATLAB for this purpose)
--> Perform the regression for the polynomial degree from degree 1 to degree 100 and display the results of these 100 experiments in the plot below.
--> This example plot shows the MSE error for each degree of polynomial for both the training set and test set.
We have generated the data in one dimension using the following code :
rng(914163506);
temp=0:.15:2*pi;
x = sin(temp)+.2*randn(size(temp));arash Mohahttps://kr.mathworks.com/matlabcentral/profile/authors/22402017tag:kr.mathworks.com,2005:Question/8293582021-05-13T17:24:20Z2021-05-13T17:30:48ZDelete all values in time series less than a certain numberI have many time series I'm looking to combine but they all have different starting and ending times. I have found the lowest/highest common times, but am not sure how to delete every value less/greater than that number. Right now I have this :
test = data{1,1}(table2array(data{1,1}(:,2))==LCT : table2array(data{1,1}(:,2))==HCT, : ); %Time is in the second column, also tried with data{1,1}.Time
I also had no success using this:
test = data{1,1};
test(test.Time < LCT && test.Time > HCT) = [ ];
I already converted the timeseries to a normal array and solved my problem in that form, but was wondering if there's a way to solve it while keeping it in timeseries form.
ThanksCristiano Iacobellihttps://kr.mathworks.com/matlabcentral/profile/authors/22353544tag:kr.mathworks.com,2005:Question/8292432021-05-13T15:22:44Z2021-05-13T17:27:54ZGenerating adjacency matrix for following networkHi Everyone,
I'd like to create random adjacency matrices for networks in the following form (see image), as you can see I have 6 nodes (n = 6) and each node must have 2 connections (degree = 2) to two other nodes chosen randomly. So the sum of each row must equal 2(or whatever value "degree" is assigned). The matrix must be symmetric with zeros along the diagonal (properties of the adjacency matrix). I have written a code that generates random adjacency matrices but Imnot sure how to constraint the program such that each node has exaclty 2 random connections.
A = zeros(n,n); % Create initial matrix
for i = 1:n
for j = 1:n
if i==j
A(i,j)=0; % Zero values in the diagonal entries
else
A(i,j)=round(rand); % Choosing random 0 and 1 values
A(j,i)=A(i,j); % Make A matrix symmetric
end
end
end
Any help is greatly appreciated, Thank you!
Nelson Amayahttps://kr.mathworks.com/matlabcentral/profile/authors/4083482tag:kr.mathworks.com,2005:Question/8293632021-05-13T17:26:01Z2021-05-13T17:26:01ZGit on Matlab onlineCan I work with Git in Matlab online? I do not see any of the features as in the desktop versionKAMAL ANTONIO ROMERO SOOKOOhttps://kr.mathworks.com/matlabcentral/profile/authors/20370782tag:kr.mathworks.com,2005:Question/8292832021-05-13T16:30:25Z2021-05-13T17:25:53ZWhat code can I use if I want to add a condition wherein if I show a picture that is not registered in the database folder it will display 'Unrecognized Face"? 🙂In the code shown below, when I show my face in the webcam, it will display my name since my face is already registered in the database. I tried to show another picture that is not registered in the database, but the result still display the name that is registered in the database like my name. My only concern is how can I display "Unrecognized Face" if I show a picture that is not registered in the database? Thank you 🙂
clc;
close;
clear
c=webcam;
load myNet1;
faceDetector = vision.CascadeObjectDetector;
while true
e = c.snapshot;
bboxes = step(faceDetector,e);
if(sum(sum(bboxes))~=0)
es=imcrop(e,bboxes(1,:));
es=imresize(es,[227 227]);
label=classify(myNet1,es);
image(e);
title(char(label));
drawnow;
else
image(e);
title('No Face Detected');
end
endJeanne Ross Abreahttps://kr.mathworks.com/matlabcentral/profile/authors/19288238tag:kr.mathworks.com,2005:Question/4335842018-12-03T17:51:35Z2021-05-13T17:25:22ZMorlet wavelet: what is the difference between 'morl' and 'amor' wavelets?Dear wavelet fan,
My question as in the title: what is the difference between 'morl' and 'amor' wavelets?
is it all the same, just different name used in the old and new 'cwt' function?
Thank you for the answer in advance!
Best, Maja
Maja Bitenchttps://kr.mathworks.com/matlabcentral/profile/authors/1912013tag:kr.mathworks.com,2005:Question/8240152021-05-07T09:12:28Z2021-05-13T17:21:34ZUnderstanding CWT Morlet: Time and frequency resolutionHello all,
I have been using a continuous 1-D wavelet transform (MATLAB cwt function) to compute and plot wavelet scalograms. For my research, I need to know the time and frequency resolution of the scalograms, but I could not find this information from any of the MATLAB documentations I looked into.
I am using 'amor' for the cwt, and it seems like 'amor' and 'cmor' operate with essentially the same equation (please correct me if I am wrong).
Complex Morlet Wavelet:
Analytic Morlet (Gabor) Wavelet: where
I am not sure if the equation for the analytic Morlet wavelet is correct since it is not documented, but given such equations, the temporal and frequency resolution for the wavelet transform then would be and , respectively, where 'a' is a scale value.
My question is what value or (or width if ) and is used to define the Morlet wavelet in the 'cwt' function.
EDIT: For 'cmor', it says that and by default. Would these values also apply for 'amor' when using 'cwt'?
Thank you very much.SungJun Chohttps://kr.mathworks.com/matlabcentral/profile/authors/22054488tag:kr.mathworks.com,2005:Question/8293382021-05-13T17:08:07Z2021-05-13T17:20:07Zi am not able to make loopsyms x y l
x0=1
y0=1
f=@(x,y) x^2+2*y^2-0.3*cos(3*pi*x)-0.4*cos(4*pi*y)+0.7
g=gradient(f(x,y))
dfdx=@(x) 2*x+(9*pi*sin(3*pi*x))/10
dfdy=@(y) 4*y+(8*pi*sin(4*pi*y))/5
sx=-dfdx(x0)
sy=-dfdy(y0)
n=1
x=x0
y=y0
for n=1:3
x=@(l) x+sx*l;
y=@(l) y+sy*l;
%f2=f(x(l),y(l));
f1= @(l) f(x(l),y(l))
gf= @(l) gradient(f1)
l=solve(gf(l))
x=x(l)
y=y(l)
end
alok ranjanhttps://kr.mathworks.com/matlabcentral/profile/authors/21927467tag:kr.mathworks.com,2005:Question/8293532021-05-13T17:19:54Z2021-05-13T17:19:54ZDisplaying an image on UIAxes in App Designer that doesn't appearHey there,
I've been trying to design a GUI in the app designer that estimates noise, it:
Takes an image specified by the user, image appears on UIAxes2
User selects a type of noise to add
Image with noise added is displayed again on UIAxes2
Please advise.
The original selected image appears just fine but when I want the noisy image to appear, it doesn't. Here are screenshots of the code + the App
Original Image code
function UploadImageButtonPushed(app, event)
[filename,filepath] = uigetfile({ '*.*;*.jpg;*.png;*.bmp;*.oct' }, 'Select File to Open');
fullname = [filepath, filename];
file = imread(fullname);
global pic
pic=im2gray(file);
image1=im2double(pic);
imshow(image1, 'parent', app.UIAxes2)
end
2. Noisy image code
% Button pushed function: ApplyNoiseButton
function ApplyNoiseButtonPushed(app, event)
global image1
global noisy
if (strcmp(app.SelectTypeofNoisetoAddDropDown.Value,'Salt & Pepper'))
noisy = imnoise(image1, 'salt & pepper');
elseif(strcmp(app.SelectTypeofNoisetoAddDropDown.Value, 'Gaussian'))
noisy = imnoise(image1, 'gaussian', 0, 0.01);
elseif(strcmp(app.SelectTypeofNoisetoAddDropDown.Value,'Speckle'))
noisy = imnoise(image1, 'speckle');
else
noisy=image1;
end
imshow(noisy,'parent', app.UIAxes2)
end
Screenshots of GUI:
Ahmed Mukhtarhttps://kr.mathworks.com/matlabcentral/profile/authors/20013607tag:kr.mathworks.com,2005:Question/8282902021-05-12T12:23:51Z2021-05-13T17:18:19ZTestbench for floating point model-hdl coderMy design consists of floating point test generator and the algorithmic model. I could generate verilog code for algorithmic model . However I need the procedure to convert the test generator as a verilog testbench so that I could check it in modelsimGaryhttps://kr.mathworks.com/matlabcentral/profile/authors/12414499tag:kr.mathworks.com,2005:Question/8293332021-05-13T17:06:37Z2021-05-13T17:16:41ZStrange curve fitting with large polynomial degrees when using polyfitI'm trying to fit a curve to my points by using polyfit, I'm getting normal results for small polynomial degrees, but when i want to use polyfit for bigger polynomial degrees, I get strange results.
This is what I get when for degree of 10:
It's okay and its normal, but when I use polyfit for the degree of 100, I get strange results for the starting points and the ending points:
What's the reason for this strange behavior? How can i fix this?
More Sahttps://kr.mathworks.com/matlabcentral/profile/authors/22539532tag:kr.mathworks.com,2005:Question/2194272015-05-27T04:00:00Z2021-05-13T17:15:33ZWhy does referece to variable size data using "coder.wref" translate to incompatible (pointer) type arguments?I am trying to use pointer references to variable size data with "coder.wref" and then generate DLL.
My current workflow can be illustrated as (please refer to the skeleton function below).
(1) functionB --> (MATLAB Coder) --> functionB.dll
(2) functionA --> (MATLAB Coder) --> functionA.dll
(3) Use functionA.dll from a client program (integrate using Visual C/C++)
<Code Listing>
%---- functionB.m ---------------------------------
function [ result ] = functionB( flg, result )
%#codegen
% Create dll using MATLAB Coder
% Input/output specification: result [:inf×3]
result = [result; rand(1,3)];
end %-functionB-%
%---- functionA.m ---------------------------------
function functionA( flg, result )
%#codegen
coder.ceval('functionB_initialize');
coder.ceval('functionB', flg, coder.wref(result) );
coder.ceval('functionB_terminate');
end %-functionA-%
As you may expect, using variable size data is used for "result" is realized as an emxArray type
and the following code is generated for functionB:
// functionB.h
extern void functionB(double flg, emxArray_real_T *result);
However, the arguments for calling the function (B) from functionA in the generated code
uses the pointer to the data field of the emxArray structure:
// functionA.c
void functionA(double flg, emxArray_real_T *result)
{
functionB_initialize();
functionB(flg, &result->data[0]);
functionB_terminate();
}
//functionB(flg, result);
To my understanding, this would simply give a "incompatible types" warning during the compilation.
If build can be successfull at all (ignoring the warning),
it is highly likely that the address of "result->data[0]" will differ from the intended address of "result"
and will produce something unexpected.
What can I do?
As an workaround I could think of manually changing the function call to
functionB(flg, result);
MathWorks Support Teamhttps://kr.mathworks.com/matlabcentral/profile/authors/4622813tag:kr.mathworks.com,2005:Question/8274252021-05-11T14:37:00Z2021-05-13T17:14:41ZPlotting line of regression analysis Hi, I'm trying to plot a line for my regression analysis on my scatter graph. I have calculated the regression using a function 'linear_regression' and it has given me the R2, slope and RMSE values as seen in the picture. How can I plot this line?
LR1=linear_regression (new_exp_wear_data,new_caliberated_pred_data );
figure(200);
scatter (new_exp_wear_data,new_caliberated_pred_data)
xlabel('experimental')
ylabel('predicted')
Mahshad Rabieehttps://kr.mathworks.com/matlabcentral/profile/authors/13874698tag:kr.mathworks.com,2005:Question/3621362017-10-19T12:46:22Z2021-05-13T17:06:21Zzeros before a string using num2strI would like to pad zeros before a string. I have the following code:
a1 = 12.1521;
a2 = 2.1521;
b1 = num2str(a1,'%03.4f');
b2 = num2str(a2,'%03.4f');
The result is b1 = '12.1521';
The result is b2 = '2.1521';
I would like to obtain the result b1 = '012.1521' and b2 = '002.1521' fdbhttps://kr.mathworks.com/matlabcentral/profile/authors/3648803tag:kr.mathworks.com,2005:Question/8293232021-05-13T17:00:41Z2021-05-13T17:02:24ZWhy would the same x and y data points be plotted differently on UIaxis (app designer)?Hello all,
I need to know something about figures in the app designer, which I am not able to understand. I am plotting two figures for the same x and y data points but those figures trun out to be different. Can anybody explain, where am I doing wrong? Here is the explanation:
Figure 1(first attachment): This is plotted (data points: x =[353 423 625]; y = [1461 1760 2614];) in a complex code.
Figure 2 (second attachment): I have plotted externally by manullay inserting those x and y data points in a much simpler code.
I do not understand why would Figure 1 and Figure 2 look different given the fact that the same data points are being plotted?
any leads will be much appreciated. Thank you.Raju Kumarhttps://kr.mathworks.com/matlabcentral/profile/authors/20583909tag:kr.mathworks.com,2005:Question/8229352021-05-06T09:23:34Z2021-05-13T17:01:49ZTrouble finding the app on Windows 10, which was created on Mac and shared!Hello all,
I have generated an app from the matlab app designer using complier on Mac but when I transfer that to Winows 10 and try to access the app, I see a folder with different file extensions instead the actual version/app.
Can anybody help with that? Where am I doing it wrong?
RajuRaju Kumarhttps://kr.mathworks.com/matlabcentral/profile/authors/20583909tag:kr.mathworks.com,2005:Question/8292232021-05-13T15:08:42Z2021-05-13T16:55:18ZHow to increase the size of a matrix within for loopHello
There is a for loop in my code.
imagine i obtain value 1 after the first iteration, so it would be my first array in the matrix CM--->so CM=[1]
then in the second iteration i obtain: [1 0.214; 0.214 1] which i want to be added to the matrix CM as
CM= [1 0 0;
0 1 0.214;
0 0.214 1]
then in the third iteration i obtain: [1 0 0; 0 1 0.0013; 0 0.0013 1] , so the matrix CM should become:
CM= [1 0 0 0 0 0;
0 1 0.214 0 0 0;
0 0.214 1 0 0 0;
0 0 0 1 0 0;
0 0 0 0 1 0.0013
0 0 0 0 0.0013 0]
and so forth.
How can i formulate this? Any help is highly appreciated.Pooneh Shah Malekpoorhttps://kr.mathworks.com/matlabcentral/profile/authors/16932213tag:kr.mathworks.com,2005:Question/8293132021-05-13T16:53:48Z2021-05-13T16:53:48ZDAQ toolbox Timeout error, PCIe-6363Morning all,
I am following the tutorial for measuring the position of a rotary encoder found here (video here) line-by-line. I also have a rotary encoder, but am using a NI PCIe-6363 as my DAQ interface. I've also followed the troubleshooting tips from Mathworks to make sure my NI-DAQmx driver version and the version of Matlab I am using are compatible. I am able to get a single read out however when I try to do a hardware timed read I always get timeout expired before operation could complete error. I've read up on a few other posts where there have been similar issues, but I am unable to find where the timeout is being set. It was suggested in one of these posts to check the command get(myDevice) where one would find the timeout option, however these were for VISA or USB devices; I don't have a timeout option except for the DigitalTriggerTimeout which I don't think is the same? (already tried changing it, did nothing). See getDevice.PNG.
Does anyone have any suggestions about how to proceed? I would love to get it working through Matlab before moving onto LabView.
Thanks!
ChrisChris Dizonhttps://kr.mathworks.com/matlabcentral/profile/authors/14122415tag:kr.mathworks.com,2005:Question/8293032021-05-13T16:43:53Z2021-05-13T16:53:35Zdsp.channelizer acts unexpectedly with oversamplingRatio=4Signal to be channelized:
Channelizer filter has normalized bandwidth of .16. Channelizer has eight channels. So without oversampling, the fringes of each .16-wide channel signal get aliased into the .125-wide channel bandwidth:
Oversampling by two clears this up nicely:
I would expect oversampling by four to do "even better", with the eight spectra getting skinnier, but no...:
Here's the code:
d=randn(250000, 1);
d=d+randn(250000, 1)*1i;
d=d+.05*exp(1i*2*pi*.10*[1:250000].');
d=d+.08*exp(1i*2*pi*.11*[1:250000].');
d=d+.11*exp(1i*2*pi*.12*[1:250000].');
figure
plot(abs(fftshift(fft(d))))
f = designfilt('lowpassfir', ...
'PassbandFrequency', .16, ...
'StopbandFrequency', .18, ...
'PassbandRipple', 1, ...
'StopbandAttenuation', 60);
for oversampling=[1 2 4]
channelizer=dsp.Channelizer('NumFrequencyBands', 8, ...
'OversamplingRatio', oversampling, ...
'Specification', 'Coefficients', ...
'LowpassCoefficients', f.Coefficients);
channels=channelizer(d);
figure
for channel=1:8
subplot(2,4,channel)
plot(abs(fftshift(fft(channels(:,channel)))))
title(sprintf("Channel %d", channel))
end
sgtitle(sprintf("Oversampling=%d", oversampling))
end
Harold Alexanderhttps://kr.mathworks.com/matlabcentral/profile/authors/17263415