https://kr.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — 새 질문2020-05-27T16:15:57Ztag:kr.mathworks.com,2005:Question/5356092020-05-27T16:15:57Z2020-05-27T16:15:57ZError in 'fsw/Reactor S-Function' while executing MATLAB S-function 'rod', flag = 1 (derivatives), at time 0.0. Index exceeds matrix dimensions.function [sys,x0,str,ts,simStateCompliance] = distill(t,y,u,flag)
switch flag,
%%%%%%%%%%%%%%%%%%
% Initialization %
%%%%%%%%%%%%%%%%%%
case 0,
[sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes();
%%%%%%%%%%%%%%%
% Derivatives %
%%%%%%%%%%%%%%%
case 1,
sys=mdlDerivatives(t,y,u);
%%%%%%%%%%
% Update %
%%%%%%%%%%
case 2,
sys=mdlUpdate(t,y,u);
%%%%%%%%%%%
% Outputs %
%%%%%%%%%%%
case 3,
sys=mdlOutputs(t,y,u);
%%%%%%%%%%%%%%%%%%%%%%%
% GetTimeOfNextVarHit %
%%%%%%%%%%%%%%%%%%%%%%%
case 4,
sys=mdlGetTimeOfNextVarHit(t,y,u);
%%%%%%%%%%%%%
% Terminate %
%%%%%%%%%%%%%
case 9,
sys=mdlTerminate(t,y,u);
%%%%%%%%%%%%%%%%%%%%
% Unexpected flags %
%%%%%%%%%%%%%%%%%%%%
otherwise
DAStudio.error('Simulink:blocks:unhandledFlag', num2str(flag));
end
% end sfuntmpl
%
%=============================================================================
% mdlInitializeSizes
% Return the sizes, initial conditions, and sample times for the S-function.
%=============================================================================
%
function [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes()
%
% call simsizes for a sizes structure, fill it in and convert it to a
% sizes array.
%
% Note that in this example, the values are hard coded. This is not a
% recommended practice as the characteristics of the block are typically
% defined by the S-function parameters.
%
sizes = simsizes;
sizes.NumContStates = 20;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 5;
sizes.NumInputs = 4;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1; % at least one sample time is needed
sys = simsizes(sizes);
%
% initialize the initial conditions
x0 = ones(20,1)*298.0;
%
% str is always an empty matrix
%
str = [];
%
% initialize the array of sample times
%
ts = [0 0];
% Specify the block simStateCompliance. The allowed values are:
% 'UnknownSimState', < The default setting; warn and assume DefaultSimState
% 'DefaultSimState', < Same sim state as a built-in block
% 'HasNoSimState', < No sim state
% 'DisallowSimState' < Error out when saving or restoring the model sim state
simStateCompliance = 'UnknownSimState';
% end mdlInitializeSizes
%==========================================================
% mdlDerivatives
% Return the derivatives for the continuous states.
%=============================================================================
%
function sys=mdlDerivatives(t,x,u)
%
% 1-D heat conduction, unsteady state
n = size(x,1);
% Inputs (3):
% Left Surface Temperature (K)
Tem(1) = u(1);
% Temperature of surroundings
%T_amb= u(2); % 298.15;
% Overall heat transfer coefficient
%h = u(3); % 2;
% Type of material (0 = silver, 1 = aluminum)
type = u(4);
material = round(type);
% States (n):
% Temperatures at points along the rod
Temp(2:n+1) = x(1:n,1)';
% Parameters:
% Radius of the rod
%radius = 0.03; % 3 cm
% Length of the rod
length = 0.10; % 30 cm
m=0.50;
theta_s=0.520;
theta_r=0.218;
alpha=0.0115;
K_s = 31.6;
% Thermal conductivity
%k_silver = [436.13 -0.011922 -0.000084465 3.3463E-08 0];
%k_alum = [165.84 0.49305 -0.0011114 9.8024E-07 -3.2368E-10];
%if material == 0;
% A = k_silver;
%else
% A = k_alum;
%end
for i = 1:n+1,
K(i)=K_s*(Temp(i)^0.5)*((1-(1-Temp(i)^(1/m))^m)^2);
end
% use the harmonic mean to estimate the thermal conductivity at the control volume borders
%for i = 1:n
% D(i)=K_s*((1-m)/(alpha*m*(theta_s-theta_r)))*((theta(i)^(0.5-(1/m)))/((1-theta(i)^(1/m))))*((1-(1-theta(i)^(1/m))^m)^2);
%end
% Solid density
%rho_silver = [102.79 -0.0186 0 0 0];
%rho_alum = [102.83 -0.00873 0 0 0];
%if material == 0;
% A = rho_silver;
%else
% A = rho_alum;
%end
for i = 1:n+1
D(i)=K_s*((1-m)/(alpha*m*(theta_s-theta_r)))*((Temp(i)^(0.5-(1/m)))/((1-Temp(i)^(1/m))))*((1-(1-Temp(i)^(1/m))^m)^2);
end
% Solid heat capacity
%cp_silver = [24710 1.14 0.00388 0 0];
%cp_alum = [22149 5.7062 0.0067408 0 0];
%if material == 0;
% A = cp_silver;
%else
% A = cp_alum;
%end
%for i = 1:n+1,
% cp(i) = A(1) + A(2)*Temp(i) + A(3)*Temp(i)^2 + A(4)*Temp(i)^3 + A(5)*Temp(i)^4;
%end
% Determine equal spacing between nodes
dx = length / n;
% Surface area for each section
%As = 2 * pi * radius * dx;
% Surface area for the end or cross-sectional areas
%Ae = pi * radius^2;
% Compute xdot:
for i = 2:n,
xdot(i-1,1) = (1/(2*(dx)^2))...
* (D(i+1)+D(i))*(Temp(i+1)-Temp(i))...
-1/(2*(dx)^2)...
*((D(i-1)-D(i))*(Temp(i)-Temp(i-1)))...
+1/dx ...
*(K(i)-K(i-1));
end
xdot(n,1) = (1/(2*(dx)^2))...
* (D(n+1)+D(n))*(Temp(n+1)-Temp(n))...
+1/dx ...
*(K(n+1));
% derivatives
sys = xdot;
% end mdlDerivatives
%
%=============================================================================
% mdlUpdate
% Handle discrete state updates, sample time hits, and major time step
% requirements.
%=============================================================================
%
function sys=mdlUpdate(t,y,u)
sys = [];
% end mdlUpdate
%
%=============================================================================
% mdlOutputs
% Return the block outputs.
%=============================================================================
%
function sys=mdlOutputs(t,y,u)
sys = [y(1) y(5) y(10) y(15) y(20)];
% end mdlOutputs
%
%=============================================================================
% mdlGetTimeOfNextVarHit
% Return the time of the next hit for this block. Note that the result is
% absolute time. Note that this function is only used when you specify a
% variable discrete-time sample time [-2 0] in the sample time array in
% mdlInitializeSizes.
%=============================================================================
%
function sys=mdlGetTimeOfNextVarHit(t,y,u)
sampleTime = 1; % Example, set the next hit to be one second later.
sys = t + sampleTime;
% end mdlGetTimeOfNextVarHit
%
%=============================================================================
% mdlTerminate
% Perform any end of simulation tasks.
%=============================================================================
%
function sys=mdlTerminate(t,y,u)
sys = [];
% end mdlTerminate
jose luis huayanay villarhttps://kr.mathworks.com/matlabcentral/profile/authors/15142725-jose-luis-huayanay-villartag:kr.mathworks.com,2005:Question/5356042020-05-27T16:05:26Z2020-05-27T16:15:52ZIn a randomly generated matrix how to find the position(row and column) of an element by using its value?Ive created a 5x5 matrix using the rand() function
A=rand(5)
0.4427 0.8173 0.8001 0.1455 0.1450
0.1067 0.8687 0.4314 0.1361 0.8530
0.9619 0.0844 0.9106 0.8693 0.6221
0.0046 0.3998 0.1818 0.5797 0.3510
0.7749 0.2599 0.2638 0.5499 0.5132
B=find(a==0.0844)
after i enter the above code for finding the position of that particular element, the output becomes " 0x1 empty double column vector "
Im literally a newbie to matlab software so kindly help mekarthikeyan vishnumohanhttps://kr.mathworks.com/matlabcentral/profile/authors/18128290-karthikeyan-vishnumohantag:kr.mathworks.com,2005:Question/3201292017-01-12T11:45:18Z2020-05-27T16:14:58ZWhat does "@" do ?So this is a simple question. I found some code that uses "@" and I looked it up in the matlab
documentation, but I did not find it to be really helpfull.
Can somebody explain to me what it does and when/how I want to use it ?H ZETT Mhttps://kr.mathworks.com/matlabcentral/profile/authors/7576524-h-zett-mtag:kr.mathworks.com,2005:Question/5352232020-05-27T09:44:51Z2020-05-27T16:14:00ZShare data between two functionsHi,
I need to update and share a variable between two functions to solve a system of ODEs. These functions are, respectively, odefun - the function that ode45 accepts as input - and myOutputFcn - that is the custom output function that ode45 accepts as option.
function dsol_dt = odefun(t, sol, hyspar, L, M)
dsol_dt = zeros(2,1);
u = sol(1,1);
y = sol(2,1);
fri = hyspar.fri;
ud = y;
yd = - L(y,fri) / M ;
dsol_dt = [ud; yd];
end
function status = myOutputFcn(t,sol,flag,hyspar)
switch flag
case 'init'
case ''
hyspar.fri = RestoringForce(sol(1),sol(2),ecc,hyspar);
case 'done'
assignin('base','hyspar.fri',fri);
end
status = 0;
end
I would share and update the variable that is hyspar.fri (fri). When it updates in myOutputFcn through the function RestoringForce, I am only changing the local copy. So, in odefun will not be taken the updated value of the variable fri.
I read the main techniques to share variables between workspaces
https://it.mathworks.com/help/matlab/matlab_prog/share-data-between-workspaces.html
but I didn't find any examples that suit me, I guess...
I would like to specify that I can't call RestoringForce in odefun for several different reasons.
Kind regards
CaliffoCaliffohttps://kr.mathworks.com/matlabcentral/profile/authors/14986138-califfotag:kr.mathworks.com,2005:Question/1100602013-12-17T21:14:18Z2020-05-27T16:13:27ZSimulink Matlab Function block
I have a Matlab workspace variable called clock_frequency.
I use this variable as a parameter in many of my simulink blocks.
I want to be able to access and alter this variable within my Simulink Matlab Function block, but I cannot do it successfully. Unlike the other simulink blocks (that can see the workspace variables) the matlab function block cannot.
I do not want to create a port and pass the variable in as a signal for various reasons.
Reading through the documentation, I have to use data store memory, but this doesn't seem to work. I got a partial version of this working, and the simulink model began running really slowly.
Jeremyhttps://kr.mathworks.com/matlabcentral/profile/authors/2740297-jeremytag:kr.mathworks.com,2005:Question/5263082020-05-18T11:02:24Z2020-05-27T16:13:09ZAllocating Resource ID for the resources in SimeventsHi,
I am building a model of automated warehouse. This model has vehicles as resource which will serve the orders. When one order is completed the resource is released and is available for the next order. Now, i am brining back all the vehicles to one location but in real time, the vehicle will be at different locations when the order is completed. For Eg: Once order is recieved the vehicle goes to the particular order tote, brings the order tote to the operator and takes back the order tote to the original location. These locations can be different for different orders.
So when the next order is generated, i want to know the position of the previous bot so that i can calculate the distance/time required for it to reach the next order location.
Is this something that i can do with simulink. Sorry if it is a noob question.
Regards,
Tashrif YusufTashrif Yusufhttps://kr.mathworks.com/matlabcentral/profile/authors/15748745-tashrif-yusuftag:kr.mathworks.com,2005:Question/3246732017-02-13T02:35:05Z2020-05-27T16:12:01ZHow can I install MATLAB on the D drive?I specified the installation folder in the D drive but the computer automatically install MATLAB in the downloads folder as default name "MathWorks" in C DRIVE even though I manually specified the destination in D drive. All other program are I can install on D drive but it seems I cannot install MATLAB on the D drive. So is it possible to install MATLAB on D drive?Takehiro Tanakahttps://kr.mathworks.com/matlabcentral/profile/authors/7453596-takehiro-tanakatag:kr.mathworks.com,2005:Question/5337832020-05-26T07:18:31Z2020-05-27T16:10:48ZPlotting Chart With 2 X Axes and 2 Y AxesHi there,
I am trying to plot various curves using semilogx along with the line of best fit. I also want to plot some other plots of semilogx on different axes (but in the same figure). I have:
ARI = ones(n,1)./P; % Average Return Interval 1/P
semilogx((ARI), Q);
p_1 = polyfit(log(ARI),Q,1); % Linear best fit
f_1 = polyval(p_1,log(ARI));
hold on
ax1 = gca; % Axis for Linear Fit
ax1.XColor = 'r';
ax1.YColor = 'r';
ax1_pos = ax1.Position; % Position of first axes
ax2 = axes('Position', ax1_pos, 'XAxisLocation','top','YAxisLocation',"right",'Color', 'none'); % Create the second axis
semilogx(ARI, f_1, '--r');
Q_100yr = polyval(p_1, log(100)) % Q value for 1 in 100 year
hold off
For some reason when I try to create the second axis, the position of the axis is not as I would like and I lose my original log curve. It ends up looking like this:
Could someone help me to get the 2 axes working.
Thanks in advance,
BrianBrian Robinsonhttps://kr.mathworks.com/matlabcentral/profile/authors/15919709-brian-robinsontag:kr.mathworks.com,2005:Question/5354882020-05-27T13:43:50Z2020-05-27T16:09:57ZHow to run this code for 1000 times?%For C1
lambda1 = [60.21, 41.58, 9.11, 8.71, 3.83, 3.74, 18.06]
r1 = poissrnd(lambda1)
%For C2
lambda2 = [41.58, 60.21, 8.71, 9.11, 3.74, 3.83, 18.06]
r2 = poissrnd(lambda2)
%Designed training sequences x1 and x2
x1 = [1,1,1,0,0,0,0,1,0,1,0,1,1,0,0,1] ;
x2 = [1,1,1,0,1,0,0,0,1,1,1,0,0,0,0,1] ;
%X[3] to X[16]
X3 = [1 1 1 1 1 1 1]' ;
X4 = [0 0 1 1 1 1 1]' ;
X5 = [0 1 0 0 1 1 1]' ;
X6 = [0 0 0 1 0 0 1]' ;
X7 = [0 0 0 0 0 1 1]' ;
X8 = [1 0 0 0 0 0 1]' ;
X9 = [0 1 1 0 0 0 1]' ;
X10 = [1 1 0 1 1 0 1]' ;
X11 = [0 1 1 1 0 1 1]' ;
X12 = [1 0 0 1 1 1 1]' ;
X13 = [1 0 1 0 0 1 1]' ;
X14 = [0 0 1 0 1 0 1]' ;
X15 = [0 0 0 0 1 0 1]' ;
X16 = [1 1 0 0 0 0 1]' ;
%X,a 7x14 matrix
X = [X3,X4,X5,X6,X7,X8,X9,X10,X11,X12,X13,X14,X15,X16];
%C, a 7x2 matrix
C = [r1; r2]' ;
%Y, a 14x2 matrix
Y = X'*C ;
%Yd = Poiss(Y) (at equation (8))
Yd = poissrnd(Y)
%y1, a 14x1 matrix ; y2, a 14x1 matrix
y1 = Y(:,1)
y2 = Y(:,2)
%Least Square Estimate of C
Cls = (inv(X*X'))*(X*Yd)
% To set to zero all the negative entries of C
Cls1 = max(Cls,0)
%Mean square error of LS C and C
MSE = mean((C - Cls1).^2)
Eric Chuahttps://kr.mathworks.com/matlabcentral/profile/authors/12596882-eric-chuatag:kr.mathworks.com,2005:Question/5346882020-05-26T22:01:41Z2020-05-27T16:06:10ZUnable to perform assignment because the indices on the left side are not compatible with the size of the right side.Hello, I have some trouble with my Newton Raphson program with two variables. I'm stuck on something that displays the message written in the title and I don't understand what doesn't work. Indeed it looks like the dimensions of err(:,i) and of abs(X-Xold) aren't the same, but I don't understant why because for me X and Xold have the same dimension, and the dimension of err(:,i) is defined after that.
X0 = [1, 1];
maxIter = 100;
tolX = 1e-6;
X = X0;
Xold = X0;
for i = 1:maxIter
[f,j] = DM2(X);
X = X - inv(j)*f;
err(:,i) = abs(X-Xold); (The error is on this line)
Xold = X;
if(err(:,i)<tolX)
break;
end
end
Also, here is my function DM2 (I don't know if it could help):
function [fval,jacobian] = DM2(X)
% Define two variables
x = X(1);
y = X(2);
% Define f(x)
fval(1,1) = y - x^3 - 1;
fval(2,1) = -6*y + 2*x^3 + 10;
% Defining the jacobian
jacobian = [3*x^2, 1;
6*x^2 , -6];
If anyone has an advice or any tips on how to solve that problem that'ld great !!!
Have a nice day all :)Rémi LEGRANDhttps://kr.mathworks.com/matlabcentral/profile/authors/17693654-remi-legrandtag:kr.mathworks.com,2005:Question/5314732020-05-23T19:32:40Z2020-05-27T16:05:40ZFRET data analysis with simulationI am having FRET data where the FRET ratio of AKAR the reporter for active PKA is calculated from the graph going from ratio 1.08 (dephosphorylated AKAR) to 1.9 (fully phos AKAR i.e AKARp)
the reaction is PKAc+AKAR4<-> PKAcAKAR4-> AKARp
i have developed a model in simbiology and want to fit the experimetal data to the output ratio of model and then calculate maximum Active PKA (PKAc) based on the ratio.
is there any example to do the same or anyone has done something similar. Parul Tewatiahttps://kr.mathworks.com/matlabcentral/profile/authors/8094727-parul-tewatiatag:kr.mathworks.com,2005:Question/2963052016-07-19T08:55:35Z2020-05-27T16:03:12ZAppdesigner window ends up in background after uigetfileI am creating a graphic program using appdesigner but when I call a function where the user can choose a file (uigetfile) the figure window is often put behind some other of my open windows after the file has been chosen. For example if I have a word document open at the same time as my program, the word document gets focus when the file has been chosen and I have to click at the bottom bar to get back to my program. I was using GUIDE before and then I didn't have that problem. I am running on Windows. Is there a way to solve this?Fredrik Wallénhttps://kr.mathworks.com/matlabcentral/profile/authors/8300904-fredrik-wallentag:kr.mathworks.com,2005:Question/5333982020-05-25T21:22:25Z2020-05-27T16:02:45ZHow to read the name of all output argument in function?It is only known the name of M-file for the main function. AAA.m define as below
[¨P1,P2,P3,...P15]=function(a1,a2,a3,..a10)
...
I just want to read the name of output arguments, P1,P2,P3,...P15 is just assumption name we don't know.
We need to output it by some code. it could be stored with a cell array or other format, it doesn't matter.
how to accomplish it? thank you.
W. Fenghttps://kr.mathworks.com/matlabcentral/profile/authors/11619170-w-fengtag:kr.mathworks.com,2005:Question/5254182020-05-14T11:03:40Z2020-05-27T16:02:12ZContinue matlab while a dos/system command is executed / close dos windowI have to use a dos-Programm where I don't have the source code. This programm controlls some measurement device via ftp.
To start the programm I call it by
answer = dos(['my_programm.exe', optionsstring])
The programm produces periodic output that is print to the matlab command window.
It runns until it is stopped by calling another exe (which writes something into a file that is read by the first...)
answer = dos(['my_end_programm.exe', optionsstring])
This works fine, if the two dos-comands are executed in a callback of a gui in Matlab2014a! Execution of 'my_programm.exe' does not block matlab. The gui stays aktive and I can press some button that triggers the 'end'-command.
However in matlab 2019b this does not work any more. The dos-command seems to block matlab. matlab waits until 'my_programm.exe' ends - which does not happen.
Also in 2014a when called from a scipt - no gui-callback - matlab gets blocked by the dos command.
Is there a way around this? Preferable in matlab 2019b or 2020?
As a workaround I use the option '&' in 2014:
answer = dos(['my_programm.exe', optionsstring, ' &'])
This opens a dos console window. The output of 'my_programm' gets there - which is aceptabel - but the window stays open. Since I call 'my_programm.exe' a couple of times this gets messy.
How can i close the dos console window?
Thank you for any help!
Joachimhttps://kr.mathworks.com/matlabcentral/profile/authors/260101-joachimtag:kr.mathworks.com,2005:Question/5344582020-05-26T17:21:39Z2020-05-27T16:01:11Zbackground removal from imageHi , I am working on a project in color illusion. And I want to remove the background from the image, the image is a person's face with white bakground, I used matlab function color thresholding to remove the background, after that I convertd the image color space to DKL space, then I started with my project, but still in my analysis the whole image is getting calculated . I want to work with the histogram of the person's face not the background. I am attaching my whole code here.. kindly help me.
2. since I am new to matlab, I learnt my codes in bits and pieces using tutorial, I want to know how to connect all my pieces together. Like starting from background removal, then using the background removed image to convert in different color space. finally using this color space image in calculating my histograms and creating illusion. so, I have written my codes in parts ... that does all this function but not together in one script. I am stuck with how to combine all these.
Kindl guide me through thisMalini Bakthavatchalamhttps://kr.mathworks.com/matlabcentral/profile/authors/17650448-malini-bakthavatchalamtag:kr.mathworks.com,2005:Question/5355992020-05-27T15:58:20Z2020-05-27T15:58:20ZMulti GPU option for LSTM/GRU LayersHello,
I know that right now it is not possible to use LSTM Layers and the multi-gpu option for the training process in Deep Learning. Is this a function that will be implemented in near future? I would realy like to use Matlab for my current research but the calculations are taking just too long with the size of the data and the current restriction of only one Geforce 1080TI.
Thanks,
BarryBarryhttps://kr.mathworks.com/matlabcentral/profile/authors/13617080-barrytag:kr.mathworks.com,2005:Question/3656622017-11-07T16:02:40Z2020-05-27T15:54:23ZGauss Seidel Method with RelaxationI am working on a matlab code using the Gauss Seidel method with relaxation to solve a system to a specified tolerance of es = 5%.
Something is wrong with my code, as I am not getting the correct output. Any help would be appreciated.
% function x=GaussSeidel_Relax_Example(lambda, es)
% Gauss-Seidel for a 3-by-3 linear system of equations
%
%--Input
% lambda: relaxation parameter
% es: error tolerance (approximate absolute percent relative error in solution)
%
%--Output
% x: Gauss-Seidel linear solution (3-by-1 vector)
% Note: 1. Use the Euclidian norm (i.e. 2-norm) to compute relative error.
% 2. You may need to rearrange the linear equations to achieve diagonal dominance.
% Write your code here.
lambda = 0.7;
es = 0.5;
Eqn1_LHS = [10 2 -1];
Eqn1_RHS = 27;
Eqn2_LHS = [-3 -6 2];
Eqn2_RHS = -61.5;
Eqn3_LHS = [1 1 5];
Eqn3_RHS = -21.5;
x = [10 10 10]; % Initial guess for the solution x
error = 1; % Initializing error
iter = 0; % number of iterations
while error > es % Running the code until actual error is greater than tolerance
x_old = x;
x(1,1) = (1-lambda) * x(1,1) + lambda * ((Eqn1_RHS - Eqn1_LHS(1,2) * x(1,2) - Eqn1_LHS(1,3) * x(1,3)) / (Eqn1_LHS(1,1)));
x(1,2) = (1-lambda) * x(1,2) + lambda * ((Eqn2_RHS - Eqn2_LHS(1,1) * x(1,1) - Eqn2_LHS(1,3) * x(1,3)) / (Eqn2_LHS(1,2)));
x(1,3) = (1-lambda) * x(1,3) + lambda * ((Eqn3_RHS - Eqn3_LHS(1,1) * x(1,1) - Eqn3_LHS(1,2) * x(1,2)) / (Eqn3_LHS(1,3)));
error = norm(x - x_old) / norm(x);
iter = iter + 1;
end
disp('Total number of iterations needed is:');
disp(iter)
end
The output I am given is 0.4685, 8.2208, -5.9833.
The correct output is 0.608679, 7.964641, -5.976428
I think I am messing up and not fully understanding making an initial guess or initializing error. Could someone please help review the code. I keep trying to work at it, but am clearly missing something. Thank you.
Amandahttps://kr.mathworks.com/matlabcentral/profile/authors/4429598-amandatag:kr.mathworks.com,2005:Question/4654082019-06-04T02:35:01Z2020-05-27T15:53:05ZPerform Google Search in MatlabHi!
I am trying to figure out how to perform a Google search automatically in matlab and save the results in an array.
Say I wanted to save the paths to the pdf files: "site:www.cnn.com filetype:pdf"
Some answers in the list should then be:
'http://www.cnn.com/2004/images/01/23/jackson.doc.pdf'
'http://www.cnn.com/StudioTour/pdf/websitefaq.pdf'
...
I have seen some scripts (links below) but unfortunately they are outdated or simply do not work. I am guessing it may be possible to do this but I cannot seem to figure it out. Any assistance would be very welcome!
Links:
https://www.mathworks.com/matlabcentral/fileexchange/41042-google
https://www.mathworks.com/matlabcentral/fileexchange/65829-google-search-answer-links
dsmalenbhttps://kr.mathworks.com/matlabcentral/profile/authors/3749917-dsmalenbtag:kr.mathworks.com,2005:Question/4338762018-12-05T01:52:00Z2020-05-27T15:49:56Zuigetfile dialog box pops up behind app windowI have created an app in the app designer in which I call uigetfile or uigetdir to load text files with data. It all works just fine, except that the dialog box to select the file/directory pops up behind the app window, and I have to move the app window aside to access the dialog box. When I'm running it on top of MATLAB (in a MATLABWindow) the dialog box appears to be associated with the main MATLAB program (the icon for the main program bounces up and down on my Mac toolbar, and when I click on it I can see the dialog box,) rather than with the app in the MATLABWindow. However, if I compile the app to run as a standalone on Mac or Windows, the dialog box still pops up behind the main app window.
Does anyone know how to fix this?Barry Bickmorehttps://kr.mathworks.com/matlabcentral/profile/authors/1400281-barry-bickmoretag:kr.mathworks.com,2005:Question/39012011-03-24T14:21:53Z2020-05-27T15:48:35ZMerging two figuresI have two figures with different plots. I would like to merge them into one figure that contains both plots and with keeping the title of the figure and axis-labels (both figures have the same title and axis-labels). How can I do this in Matlab? I should also add that I am not interested in "do-by-hand" solution. Mateuszhttps://kr.mathworks.com/matlabcentral/profile/authors/1953895-mateusztag:kr.mathworks.com,2005:Question/2525742015-11-03T19:40:11Z2020-05-27T15:48:22ZDerivative of state '1' in block 'X/Y/Integrator' at time 0.55 is not finite.An error occurred while running the simulation and the simulation was terminated
Caused by:
Derivative of state '1' in block 'X/Y/Integrator' at time 0.55 is not finite. The simulation will be stopped. There may be a singularity in the solution. If not, try reducing the step size (either by reducing the fixed step size or by tightening the error tolerances).
How to fix this error?Revathi Medahttps://kr.mathworks.com/matlabcentral/profile/authors/7048386-revathi-medatag:kr.mathworks.com,2005:Question/5342732020-05-26T15:02:54Z2020-05-27T15:42:53ZShould mvnrnd Always Advance the State of the Global StreamConsider the following:
>> mu=[1 1]; Sigma=eye(2);
rng('default')
preu1 = rand(1,3);
n1 = mvnrnd(mu,Sigma);
u1 = rand(1,3);
rng('default')
preu2 = rand(1,3);
n2 = mvnrnd(mu,Sigma);
u2 = rand(1,3);
rng('default')
n3 = mvnrnd(mu,0*Sigma);
u3 = rand(1,3);
>> [isequal(u1,u2) isequal(u2,u3) isequal(u3,preu2)]
ans =
1×3 logical array
1 0 1
Apparently mvnrnd doesn't actually call randn if it detects that the input covariance is zero. That may be good for efficiency, but is it the best behavior for repeatability? This behavior seems to be a contradiction to the general direction of how to manage the Global Stream to reproduce results. doc mvnrnd is silent on how it handles this special case. Paulhttps://kr.mathworks.com/matlabcentral/profile/authors/35216-paultag:kr.mathworks.com,2005:Question/2546902015-11-13T05:00:00Z2020-05-27T15:42:34ZHow can I display a MATLAB table in a figure?I have a MATLAB table where each of the variables contains a single column of data. How can I display the table in a figure?
MathWorks Support Teamhttps://kr.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:kr.mathworks.com,2005:Question/4533282019-03-29T19:05:56Z2020-05-27T15:40:56ZASSIGNMENT: TEXT FILES Write a function called char_counter that counts the number of a certain character in a text file. The function takes two input arguments, fname, a char vector of the filename and character, the char it counts in the file. When testing with '' your solution returned -1 which is incorrect. (0)
This error pops up while doing the assignment.
can anyone tell me why is this error popping and the meaning of the statement mentioned above.
when the character is ' " ' then i get a finite answer. and when the character is ' ' ' then too answer is a finite number. but i dont understand what the above bold text means....
my code
function charnum = char_counter(fname,character)
fid=fopen(fname);
if fid< 0
charnum = -1;
return;
end
if strcmp(character,'')==1
charnum=0;
return;
end
if double(character)>=35 && double(character)<=43 && double(character) ~=39 && double(character) ~= 41 && double(character) ~= 40
charnum = 0;
return;
end
if double(character) >=60 && double(character) <=64 && double(character) ~= 63
charnum = 0;
return;
end
if double(character) == 81 || double(character) == 88 || double(character) == 90
charnum = 0;
return;
end
cc = fgets(fid);
sumv=0;
while ischar(cc)
z = sprintf('%s',cc);
k = strfind(z,character);
sumv = sumv + length(k);
cc = fgets(fid);
end
charnum = sumv;
if charnum == 0
charnum =-1;
return;
endRakshith Rhttps://kr.mathworks.com/matlabcentral/profile/authors/15060157-rakshith-rtag:kr.mathworks.com,2005:Question/5344982020-05-26T17:39:57Z2020-05-27T15:40:35Zimage changing gui matlabHi, I´d like to make a code that displays an image in a gui from a vector. I mean, I´ve got a vector that has the values 0,1,2 and I need to display in a gui an image depend on the value. I´ve got no idea to make this. Thank you.Fco. Javier Rodríguez Mirahttps://kr.mathworks.com/matlabcentral/profile/authors/17593338-fco-javier-rodriguez-miratag:kr.mathworks.com,2005:Question/558512012-12-06T02:02:12Z2020-05-27T15:38:53ZHow to generate inphase and quadrature phase of a signal?I was trying to simply create I Q components of a signal and to recover the signal from these I Q data.
But how to create I Q? is it possible by multiplying signal with sin and cos? or by taking samples at 4 points (0,90,180,270)??Akhilhttps://kr.mathworks.com/matlabcentral/profile/authors/3788030-akhiltag:kr.mathworks.com,2005:Question/5261572020-05-17T16:46:26Z2020-05-27T15:38:21Z3D matrix and 3d plot in matlabI want to use the repmat function to copy the velocity profile along a pipe for 30 times in order to make the geometry of pipe.
my code below generate the velocity profile for Poisuielle flow inside the pipe using meshgrid and mesh functions.
Please help me how to write the repmat to generate the pipe geometry.
R = 0.003/2; %pipe dia.
yy=linspace(-R,R,50);
xx=yy';
r=sqrt(xx.^2+yy.^2);%pipe redius as function of x , y
z=-(f1.a0)*(R^2-(xx.^2+yy.^2))/0.016;% velocity profile in z direction(along the pipe),f1.a0=constant
[X1,Y1]=meshgrid(xx,yy);
figure
mesh(X1,Y1,z)
colorbar
contour(X1,Y1,z)H-Mhttps://kr.mathworks.com/matlabcentral/profile/authors/17915351-h-mtag:kr.mathworks.com,2005:Question/5336682020-05-26T04:04:41Z2020-05-27T15:36:22ZHow to add 3rd Y-axis at right side?I wish to add a 3rd y-axis on the right side to plot the blue line, Can anyone guide me how should I do it?
Thank you!
data = xlsread("sampleexceldata.xlsx") ;
K = data(1,[1 3 5]); % factors
data(1,:) = [];
s1 = data(2:20,1) ; f1 = data(2:20,2) ;
s2 = data(2:9,3) ; f2 = data(2:9,4) ;
s3 = data(2:11,5) ; f3 = data(2:11,6) ; % rows with numerical values, not with NAN
figure(1)
yyaxis right
ylabel('Force');
[s3,al,idx] = unique(s3,'stable'); % identify the non duplicate values
f3 = f3(al);
[s2,al,idx] = unique(s2,'stable'); % identify the non duplicate values
f2 = f2(al);
hold on
axis tight
plot(s3,f3,'o')
plot(s2,f2,'+')
%axis ([0 5 -40 90])
theta_max = 2* pi ;
theta_min = 0 ;
theta = linspace(theta_min, theta_max,8)' ;
theta_3 = linspace(theta_min, theta_max,7)' ;
N_terp = 1024;
theta_2 = linspace(theta_min,theta_max,N_terp)' ;
X_terp3 = spline (theta, s3, theta_2);
Y_terp3 = spline (theta, f3,theta_2);
X_terp2 = spline (theta_3, s2, theta_2);
Y_terp2 = spline (theta_3, f2,theta_2);
hold on
axis tight
plot(X_terp3,Y_terp3,'-r')
plot(X_terp2,Y_terp2,'-b')
yyaxis left
ylabel('Force ');
[s1,al,idx] = unique(s1,'stable'); % identify the non duplicate values
f1 = f1(al);
%axis ([0 6 -15 15])
hold on
axis tight
plot(s1,f1,'*')
theta_max = 2* pi ;
theta_min = 0 ;
theta_4 = linspace(theta_min, theta_max,17)' ;
N_terp = 1024;
theta_2 = linspace(theta_min,theta_max,N_terp)' ;
X_terp1 = spline (theta_4, s1, theta_2);
Y_terp1 = spline (theta_4, f1,theta_2);
hold on
axis tight
plot(X_terp1,Y_terp1,'-g')
hold on
xlabel('Displacement (mm)');
title('Force vs Displacement')
grid on
Ashvinder Singh Gill Surmaish Singh Gillhttps://kr.mathworks.com/matlabcentral/profile/authors/11246858-ashvinder-singh-gill-surmaish-singh-gilltag:kr.mathworks.com,2005:Question/5264712020-05-19T00:46:36Z2020-05-27T15:33:12ZReinforcement Learning -- Rocket LanderTh "Rocket Lander" example does not converge with the stated hyperparameters. Someone was helpful enough to give me the following values:
learning rate = 1e-4
clip factor = 0.1
mini-batch size = 128
Although these values work better, the algorithm still does not converge. After about 14,000 episodes there are many successful landings, but they are interspersed with violent crash landings. Anybody at MathWorks or otherwise have any suggestions? Thank you.
Averill M. LAWAverill Lawhttps://kr.mathworks.com/matlabcentral/profile/authors/14159548-averill-lawtag:kr.mathworks.com,2005:Question/5355942020-05-27T15:32:54Z2020-05-27T15:32:54ZVector type output from MATLAB function in Simulink - ErrorsHello all,
I have been trying to work out how to implement a vector of any size (1xn) with MATLAB functions in Simulink. For the purposes of this question, let's take a simple test model found in the attached image.
In the first MATLAB function, I have the following simple code:
function y = fcn(u)
if(u == 1)
a = zeros(1,6);
y = a;
end
end
In the second MATLAB function, I have the following code:
function k = fcn(u1)
if(u1(1) == 0)
k = 2;
end
end
Based on answers on relative previous questions in the forum, I have the following settings regarding the variables in both MATLAB function:
However, I get the following errors when I try to run the model:
Output argument 'k' is not assigned on some execution paths.
Function 'MATLAB Function1' (#2181.9.10), line 1, column 10:
"k"
Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Errors occurred during parsing of MATLAB function 'untitled/MATLAB Function1'
Component:MATLAB Function | Category:Coder error
Output argument 'y' is not assigned on some execution paths.
Function 'MATLAB Function' (#2174.9.10), line 1, column 10:
"y"
Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Errors occurred during parsing of MATLAB function 'untitled/MATLAB Function'
Component:MATLAB Function | Category:Coder error
Errors occurred during parsing of MATLAB function 'untitled/MATLAB Function'
Component:Simulink | Category:Model error
Any ideas what I am doing wrong?
Thanks,
ChristosChristos Patrinoshttps://kr.mathworks.com/matlabcentral/profile/authors/6259253-christos-patrinostag:kr.mathworks.com,2005:Question/5355892020-05-27T15:31:16Z2020-05-27T15:31:16Zhow to prepare 3D nifti images for 2D semantic segmentation network trainingHi,
I have a bunch of 3D nifti images (which every image composed of multipule 2D images, i.e: 512 x 512 x 150). I also have a deep learning training network for semantic segmentation of 2D images (512 x 512). Do I need to extract from each 3D nifti image - a bunch of PNG images to use them as inputs to the network? Or can I use them as nifti type? if so - how?
code examples will be great! YAhttps://kr.mathworks.com/matlabcentral/profile/authors/15841877-yatag:kr.mathworks.com,2005:Question/5347582020-05-26T23:24:38Z2020-05-27T15:31:10ZMulti Threads operation SERIAL PORT in ParallelHi guys,
I hope you're all safe and healthy during this period.
I have something to ask you. I need to open two serialport objects in order to communicate with 2 Arduinos. One of that has to send me Data every 10 ms (100Hz) and the other one each 100us (10KHz). These data reiceved have to be synchronize. I wouldn't like to use 2 PCs and I'd like to know if there's some way to read data in this way.
So basically 2 obj and 2 Arduino to read at the same moment. I need to do post analysis and they need to be sync.
Thanks a lot, your help will be really appreciated.valiohttps://kr.mathworks.com/matlabcentral/profile/authors/12361912-valiotag:kr.mathworks.com,2005:Question/5254912020-05-14T16:30:24Z2020-05-27T15:30:55ZThe CNN model only predicts a single class out of three?Hello,
I am working on training a CNN model for pavement distress identification using image classification. I have three categories for defects (Alligator Cracks, Potholes and Rutting). When I run my model it only predicts a single class out of three rendering my model accuracy to 33.33%. I tried changing the training parameters/ options but the result is same. I was hoping if someone can help me figure out why. The code I am using is given below. Thanks in advance.
_______________________________________________________________________________________________________________________________________
rootFolder = fullfile ('CNN Input');
categories = {'Alligator Cracks','Potholes','Rutting'};
imds = imageDatastore (fullfile (rootFolder,categories), 'LabelSource', 'Foldernames');
tbl = countEachLabel (imds);
minSetCount = min(tbl{:,2});
countEachLabel(imds);
AlligatorCracks = find(imds.Labels == 'Alligator Cracks',1);
Potholes = find(imds.Labels == 'Potholes',1);
Rutting = find(imds.Labels == 'Rutting',1);
net = alexnet ();
rng ('default');
net.Layers(1);
net.Layers(end);
numel(net.Layers(end).ClassNames);
[trainingSet, testSet, validationSet] = splitEachLabel(imds,0.75,0.15,'randomize');
imageSize = net.Layers(1).InputSize;
augmentedTrainingSet = augmentedImageDatastore(imageSize,trainingSet,'ColorPreprocessing','gray2rgb');
augmentedTestSet = augmentedImageDatastore(imageSize,testSet,'ColorPreprocessing','gray2rgb');
augmentedValidationSet = augmentedImageDatastore(imageSize,validationSet,'ColorPreprocessing','gray2rgb');
w1 = net.Layers(2).Weights;
w1 = mat2gray(w1);
featurelayer = 'drop7';
trainingFeatures = activations(net, augmentedTrainingSet, featurelayer,'MiniBatchSize', 32,'OutputAs', 'columns');
options = trainingOptions('sgdm', ...
'LearnRateSchedule','piecewise',...
'LearnRateDropFactor',0.2,...
'learnRateDropPeriod',1,...
'MaxEpochs',8,...
'MiniBatchSize',16,...
'Plots','training-progress',...
'Shuffle','once');
numClasses = 3;
layersTransfer = net.Layers(1:end-3);
layers = [
layersTransfer
fullyConnectedLayer(numClasses,'WeightLearnRateFactor',20,'BiasLearnRateFactor',20)
softmaxLayer
classificationLayer];
trainedNet = trainNetwork(augmentedTrainingSet,layers,options);
trainingLabels = trainingSet.Labels;
classifier = fitcecoc(trainingFeatures, trainingLabels, 'Learner', 'Linear', 'Coding', 'onevsall','observationsIn','columns');
testFeatures = activations(trainedNet,augmentedTestSet, featurelayer,'MiniBatchSize', 32,'OutputAs', 'columns');
validationFeatures = activations(trainedNet,augmentedValidationSet, featurelayer,'MiniBatchSize', 32,'OutputAs', 'columns');
predictLabels = predict(classifier,testFeatures,'ObservationsIn','columns');
predictLabelss = predict(classifier,validationFeatures,'ObservationsIn','columns');
testLables = testSet.Labels;
validationLables = validationSet.Labels;
confMat = confusionmat(testLables, predictLabels);
confMatt = confusionmat(validationLables, predictLabelss);
confMat = bsxfun(@rdivide, confMat, sum(confMat,2));
confMatt = bsxfun(@rdivide, confMatt, sum(confMatt,2));
mean(diag(confMat));
mean(diag(confMatt));Vinay Chawlahttps://kr.mathworks.com/matlabcentral/profile/authors/18159066-vinay-chawlatag:kr.mathworks.com,2005:Question/5355762020-05-27T15:14:41Z2020-05-27T15:28:29ZSolving 2D PDE I have a PDE of the form
Is there a way I can solve this numerically at steady state (I'm only interested in the steady state) using the pde toolbox? Or will I need to write my on scheme to solve it? Ideally I would also like to be able to solve this with 3,4,5,6,7... independent variables. I know the analytic expressions for A,B,C,D,E.Alexander Holmeshttps://kr.mathworks.com/matlabcentral/profile/authors/4933974-alexander-holmestag:kr.mathworks.com,2005:Question/5350782020-05-27T08:05:55Z2020-05-27T15:24:49ZSolving system of equationsHi all
i have a question about solving this system of equations. Tt, Pt and M are related to space and time due to i and j; i want to solve the system maintaining that dependence, so the result will be a matrix respectively for Tt, Pt and M. When i try to solve, i obtain "Out of range subscript." error. gamma, deltax and deltat are constant
Thanks to all
Tt=zeros(length(x),length(t));
Pt=zeros(length(x),length(t));
M=zeros(length(x),length(t));
Tt(1,1)=3.000555630247608e+02;
Pt(1,1)=2.201018491400215e+05;
M(1,1)=0.023565919700319;
for j=1:length(t)-1
for i=2:length(x)-1
Alla = cell(length(x),length(t));
Allb = cell(length(x),length(t));
Allc = cell(length(x),length(t));
syms Tt Pt M
[sola,solb,solc]=vpasolve(Tt(i,j+1)==0.5*(Tt(i+1,j)-Tt(i-1,j))+((1+((gamma-1)/2)*M(i,j)^2)^(gamma/(gamma-1)))*((Tt(i+1,j)-Tt(i-1,j))*deltat/(2*deltax))+((1+((gamma-1)/2)*M(i,j)^2))*((Pt(i+1,j)-Pt(i-1,j))*deltat/(2*deltax)),...
Pt(i,j+1)==0.5*(Pt(i+1,j)-Pt(i-1,j))+2*((1+((gamma-1)/2)*M(i,j)^2)^(gamma/(gamma-1)))*((Tt(i+1,j)-Tt(i-1,j))*deltat/(2*deltax))+3*((1+((gamma-1)/2)*M(i,j)^2))*((Pt(i+1,j)-Pt(i-1,j))*deltat/(2*deltax)),...
M(i,j+1)==0.5*(M(i+1,j)-M(i-1,j))+2*((1+((gamma-1)/2)*M(i,j)^2)^(gamma/(gamma-1)))*((Tt(i+1,j)-Tt(i-1,j))*deltat/(2*deltax))+3*((1+((gamma-1)/2)*M(i,j)^2))*((Pt(i+1,j)-Pt(i-1,j))*deltat/(2*deltax)));
Alla{i,j} = sola;
Allb{i,j} = solb;
Allc{i,j} = solc;
end
endmarco pinnahttps://kr.mathworks.com/matlabcentral/profile/authors/8447926-marco-pinnatag:kr.mathworks.com,2005:Question/5322382020-05-24T19:14:48Z2020-05-27T15:24:32ZProblem continuation with the custom target of stm32f429 card?dear friends
I am stuck in the continuation of the creation of the target matlab for stm32f429, the zip file contains the following folder:
1- externalmode error: it contains two error files, one from the matlab test report and the other from the simulink diagnostic phase.
2- file rtiostrem_serial: it contains the original file (rtiostrem_serial => it includes the call to the file LM3S6965.h), it also includes the modified file (rtiostrem_serial => I replaced the command #include "LM3S6965.h" by #include "stm32f429xx.h".
3- pil error: this file contains the report of the pil test of matlab.
4- video: this video shows the progress of the entire simulation.
dear friend if possible can you help me on this problem too and thank you.
cordially
ramziramzi ben messaoudhttps://kr.mathworks.com/matlabcentral/profile/authors/9405281-ramzi-ben-messaoudtag:kr.mathworks.com,2005:Question/5355842020-05-27T15:24:28Z2020-05-27T15:24:28ZOnline course fundamentals 6.5 Using statistical operations task 3 and 4 bar not workingbar not working see title
Tried task reset.
Got the correct answer for task 3 but bar chart is wrong.
Task 4, can't get correct answer even when using the solutionBob Hayhttps://kr.mathworks.com/matlabcentral/profile/authors/5310733-bob-haytag:kr.mathworks.com,2005:Question/3519502017-08-08T08:17:19Z2020-05-27T15:23:50ZDeep learning error Lot of files openHi
I am training a 6 layers CNN for 3 class classification. Each image is resized to [90 70]. Total 4000 images for training. My PC is with i7, 32GB RAM. But no GPU.
When I am training for more than 30 epochs, I am getting error that too many files are open. In the same session, I cannot run even one epoch. See attached snapshot.
But, If I close the Matlab session and rerun, Program once again upto 30 epochs only. The RAM is also not 50% full. Why am I getting this error and how to fix it.
Thank you for help in advance.
with regards
Ramana
PS: Code is as follows
%CNN for train val sets
digitDatasetPath = fullfile('E:\Database\resize\train');
trainDigitData = imageDatastore(digitDatasetPath, ...
'IncludeSubfolders',true,'LabelSource','foldernames');
img = readimage(trainDigitData,1);
digitDatasetPath = fullfile('E:\Database\resize\val');
testDigitData = imageDatastore(digitDatasetPath, ...
'IncludeSubfolders',true,'LabelSource','foldernames');
%%
layers = [imageInputLayer([size(img,1) size(img,2) 1]);
convolution2dLayer(5,20);
reluLayer();
maxPooling2dLayer(2,'Stride',2);
fullyConnectedLayer(3);
softmaxLayer();
classificationLayer()];
options = trainingOptions('sgdm','MaxEpochs',30,'InitialLearnRate',0.0001,'ExecutionEnvironment','cpu');
rng('default')
convnet = trainNetwork(trainDigitData,layers,options);
YTest = classify(convnet,testDigitData);
TTest = testDigitData.Labels;
accuracy = sum(YTest == TTest)/numel(TTest)
disp('All over')Venkat Rhttps://kr.mathworks.com/matlabcentral/profile/authors/223861-venkat-rtag:kr.mathworks.com,2005:Question/5236912020-05-07T10:51:18Z2020-05-27T15:22:13ZComparing multiple images ( via edge detection or strongest gradient between dark and light)Hello guys,
first of all : i am very new to matlab so dont blame me for asking.
I want to compare some pictures ( 5 pictures or so ).I am testing a light,every hour i take a photo and then compare them to see if the'cut-off' did move. And if the 'cut off' moves, I'd like to see how much it shifted.
Every little adive would help me !
( I uploadet the picutre. In my test, the pictures will loke the same. But maybe afters 3 hours the 'cut-off will shift minimal. And thats what i wanna se. Like if i could get a number in the end like 2 == It shifted 2 millimeters.)
THX GUYS !Arb2493https://kr.mathworks.com/matlabcentral/profile/authors/18411597-arb2493tag:kr.mathworks.com,2005:Question/3388392017-05-05T07:40:06Z2020-05-27T15:20:59ZPlotting subplot in real time ProblemI am interfacing Arduino with MATLAB through serial plot. I have an accelerometer that input three values each time into the serial plot. I am trying to plot the 3 channel data into 3 separate subplot in real time. For some reason, only my last subplot will continuous scroll and the first two will stay at one scroll window.
if(scrollWidth > 0)
set(plotgraph1,'XData',time(time > time(count)-scrollWidth),...
'YData',datax(time > time(count)-scrollWidth));
xlim([time(count)-scrollWidth time(count)]);
set(plotGraph2,'XData',time(time > time(count)-scrollWidth),...
'YData',datay(time > time(count)-scrollWidth));
xlim([time(count)-scrollWidth time(count)]);
set(plotGraph3,'XData',time(time > time(count)-scrollWidth),...
'YData',dataz(time > time(count)-scrollWidth));
xlim([time(count)-scrollWidth time(count)]);
end
<</matlabcentral/answers/uploaded_files/76977/Screen%20Shot%202017-05-05%20at%2012.39.13%20AM.png>>
Lok Yiu Tohttps://kr.mathworks.com/matlabcentral/profile/authors/6054450-lok-yiu-totag:kr.mathworks.com,2005:Question/5355722020-05-27T15:13:38Z2020-05-27T15:17:31Zconnecting image extreme (end) boundriesHi, I have edge detected image. I want to connect all the pixels at extreme edges and fill the region inside, so that i have a binary mask of this image without any gaps. I used imdilate but this introduce thickness in boundries that i do not want in image. Can anyone please guide how I can do it. thanks
Iram Shahzadihttps://kr.mathworks.com/matlabcentral/profile/authors/7828978-iram-shahzaditag:kr.mathworks.com,2005:Question/5352782020-05-27T10:20:42Z2020-05-27T15:15:40Zfast delete of rows in a tablehi
I've got a table with 120k rows, and I need to delete some rows if there is a specific condition.
I wrote this:
for i=1:(size(db,1)-1)
if db.INTERVENTION(i)==1 && isequal(db.SETTLEMENTDATE(i-1),db.SETTLEMENTDATE(i)) && isequal(db.DUID(i-1),db.DUID(i))
db(i-1,:)=[];
end
end
This code takes a long time to execute.
Is there a faster way?
thanks!Francesco Giuseppe Fornarihttps://kr.mathworks.com/matlabcentral/profile/authors/11792707-francesco-giuseppe-fornaritag:kr.mathworks.com,2005:Question/5355602020-05-27T14:59:16Z2020-05-27T15:14:51ZEliminate certain entries of cell arrayI have a 1x73 cell array, FR, and I would like to eliminate FR {8, 17, 31, 41, 43, 47, 49, 56, 60, 66, 73} and re-save as a 1x62 cell array. How can I do this? Mary Hemlerhttps://kr.mathworks.com/matlabcentral/profile/authors/16013606-mary-hemlertag:kr.mathworks.com,2005:Question/3246462017-02-12T22:07:19Z2020-05-27T15:13:15ZHistogram of color imageI hide message inside image using LSB .It is work but
I get a different style of output of histogram.how to solve it?
<</matlabcentral/answers/uploaded_files/69680/s.png>>
my code is:
subplot(4, 4, 2);
Red = coverimage(:,:,1);
Green = coverimage(:,:,2);
Blue = coverimage(:,:,3);
%Get histValues for each channel
[yRed, x] = imhist(Red);
[yGreen, x] = imhist(Green);
[yBlue, x] = imhist(Blue);
%Plot them together in one plot
plot(x, yRed, 'Red', x, yGreen, 'Green', x, yBlue, 'Blue');
title('Histogram of Cover image ', 'FontSize', fontSize);
subplot(4, 4, 4);
Red = stegoimage(:,:,1);
Green = stegoimage(:,:,2);
Blue = stegoimage(:,:,3);
[yRed1, x1] = imhist(Red);
[yGreen1, x1] = imhist(Green);
[yBlue1, x1] = imhist(Blue);
plot(x1, yRed1, 'Red', x1, yGreen1, 'Green', x1, yBlue1, 'Blue');
title('Histogram of Stego image ', 'FontSize', fontSize);
hudof najeebhttps://kr.mathworks.com/matlabcentral/profile/authors/9312715-hudof-najeebtag:kr.mathworks.com,2005:Question/5353482020-05-27T11:35:42Z2020-05-27T15:12:59Zcan't update matlab 2020aWhen trying to update matlab 2020a got "Something unexpected occurred" error - log data provided below.
(May 27, 2020 14:21:18) Stopping task MATLAB R2020a Startup Accelerator
(May 27, 2020 14:21:40) Something unexpected occurred.: This is not common.
To resolve this issue, contact Technical Support.
at com.mathworks.update_installer.ExceptionHandlerImpl.createUpdateInstallerException(Unknown Source)
at com.mathworks.update_installer.ExceptionHandlerImpl.processException(Unknown Source)
at com.mathworks.update_installer.UpdateInstallerService.updateInstallation(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.mathworks.installservicehandler.JsonPassThroughResponseWrapper.getData(JsonPassThroughResponseWrapper.java:24)
at com.mathworks.installservicehandler.JsonPassThroughResponseWrapper.getData(JsonPassThroughResponseWrapper.java:10)
at com.mathworks.laisserver.impl.helper.RequestHandler.handleRequest(RequestHandler.java:44)
at com.mathworks.laisserver.impl.JsonServlet.doPost(JsonServlet.java:27)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:755)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:669)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:457)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:557)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1075)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:384)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1009)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
at org.eclipse.jetty.server.Server.handle(Server.java:364)
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:488)
at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:943)
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:1004)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:861)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:628)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.net.SocketTimeoutException: connect timed out
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:666)
at sun.net.NetworkClient.doConnect(NetworkClient.java:175)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:463)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:558)
at sun.net.www.protocol.https.HttpsClient.(HttpsClient.java:264)
at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1199)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1050)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:162)
at com.mathworks.instutil.URLConnectionFactoryImpl.createURLConnection(URLConnectionFactoryImpl.java:31)
at com.mathworks.instutil.DownloaderImpl.downloadFile(DownloaderImpl.java:55)
at com.mathworks.instutil.DownloaderImpl.download(DownloaderImpl.java:42)
at com.mathworks.install_impl.input.UpdateComponentDownloader.download(Unknown Source)
at com.mathworks.install_impl.InstallableComponentImpl.download(Unknown Source)
at com.mathworks.install_impl.ProductInstallerImpl.updateProducts(Unknown Source)
at com.mathworks.install_impl.InstallerImpl.update(Unknown Source)
at com.mathworks.install_task.UpdateTask.execute(UpdateTask.java:46)
at com.mathworks.install_task.AbstractDefaultInstallTask.call(AbstractDefaultInstallTask.java:24)
... 35 more
(May 27, 2020 14:26:54) Update session complete.Nikita Gvardihttps://kr.mathworks.com/matlabcentral/profile/authors/13940910-nikita-gvarditag:kr.mathworks.com,2005:Question/1550002014-09-16T09:16:33Z2020-05-27T15:12:46Zmulti seed region growingdear matlabers
i am looking for a multi seed region growing algorithm but still no luck
can anyone help? or share the codes?
thanksMEHRDAD moghbelhttps://kr.mathworks.com/matlabcentral/profile/authors/3295865-mehrdad-moghbeltag:kr.mathworks.com,2005:Question/5196522020-04-21T17:47:42Z2020-05-27T15:12:12ZUsing an external hard to run a bigger simulationSooo I have been trying to do a simulation to produce some plots for some time now and it is now apparent that I need to use a bigger matrix to get what I want. This question is concerned with is there a way to use more memory to do this?
The issue is MATLAB seems to shut itself down when I try and run my code for a big matrix (which in my work corresponds to a lattice size). I have a terabyte of RAM available on my Linux OS and another terabyte on a Windows OS. I tried repartitioning my hard drive to give my Linux OS more RAM to work with, but Windows will only let me shrink it's hard drive by 1 GB... Where I wanted to do 500 GB.
My first option is to get rid of the partition to get more RAM. Would this help with bigger simulations? I still want windows for various reasons.
I have a 2 terabyte external hard drive, so is there a way that I can use this to help MATLAB out? I would prefer this if possible! Hopefully someone can answer this since I need to start getting some good results!Marcus Rosaleshttps://kr.mathworks.com/matlabcentral/profile/authors/7835065-marcus-rosalestag:kr.mathworks.com,2005:Question/3686922017-11-22T21:36:31Z2020-05-27T15:11:21ZStop Simulink simulation when reached an oscillating steady state amplitudeHello,
I would like stop a Simulink simulation if a signal reach the steady state in terms of amplitude of oscillations: at the start of the simulation the signal have got a generic transitory, but after some time the system reach the equilibrium and so the system reach steady state like approximativelly a sin(x) function with a constant amplitude.
I would like to compare the heigth relative difference between two near peaks and compare it by a threshold percentage, but I don't know how to do it. If someone have other ideas, please tell me.
Obviously this example is not usefull in this case, because I want to find a steady state of an oscillating system, and NOT a steady state of a signal that reach a target value.
To understand better what I mean, you can see two dinstinct examples (what I want to get is stop the simulation at green line time since signals are are dynamic steady state).
Alberto Morahttps://kr.mathworks.com/matlabcentral/profile/authors/10028030-alberto-moratag:kr.mathworks.com,2005:Question/5124552020-03-23T17:16:29Z2020-05-27T15:10:51ZMATLAB R2020a won't even install on macOS CatalinaHey! After experiencing some problems with version R2019b on my MacBook (macOS Catalina), and knowing that these issues are well known, I tried to replace that version with the newest R2020a, but I couldn't even install it. After downloading and unzipping it, I try to execute the file InstallForMacOSX, I enter my computer's password and then the MATLAB logo appears and won't do anything more. Could anyone help me? Thanks in advance.
JavierJAVIER QUESADA FUNEShttps://kr.mathworks.com/matlabcentral/profile/authors/14215376-javier-quesada-funestag:kr.mathworks.com,2005:Question/5355682020-05-27T15:10:37Z2020-05-27T15:10:37ZODE23s, Differential equation, problem solvingHello everybody. I have a serious problem solving the diff. equation, expressed below. Any help;
function [kap, alf0, Pstar, Astar]= nofilter()
imu=sqrt(-1);
rho=1000;RR=0.3;
Jb=0.1; %diastato
CC=0.1;%diastato
chr=0.1;
cht=0.1;
U=0.5;
span=0.34/2;
alam1=90;
alam2=90;
chm=0.5*(chr+cht);
span3d=2*span;
area=2*(chm*span);
AR=(span3d^2)/area;
AR=10;
B=14.75; %adiastato
BB=B*rho*U*0.34*chr*chr*RR; %diastato
pic=0.25;
II=Jb/pi*rho*area*chr*chr*chr; %adiastato
C=CC/1/2*pi*rho*area*chr*U^2; %adiastato
a=span3d*RR^2/chr*area;
b=RR^2/chr^2;
e=RR/chr;
d=RR*span3d/area;
alf0=linspace(1, 60, 2);
kap=linspace(0.025,0.2,2);
for i=1:length(alf0)
for j=1:length(kap)
om(j)=pi*kap(j)*2*U/chr; % reduced velocity k, Huxham, k=pi*khuxham
T(j)=2*pi/om(j);
alf0r(i)=alf0(i)*pi/180;
theo(j)=besselh(1,2,kap(j))./(besselh(1,2,kap(j))+imu*besselh(0,2,kap(j))); %theo function, lift deficiency factor
Re=U*chr*10^6; %reynolds
CD0=0.075/(log10(Re)+2)^2; %skin friction
fprintf('Calculating for %d\n', i, j);
[t,y]=ode23s(@(t,y) nofilter(t,y, i, j), [0 , 100],[0, 0]);
[Astar(i,j), Pstar(i,j)] = processsignal(t,y);
Pstar(i,j) = 0.5*BB.*(Pstar(i,j))./0.5*rho* 2*RR.*(Astar(i,j)).*cos(((Astar(i,j)))).*U^3;
end
end
function dYdt=nofilter(t,Y, i, j)
thi(i,j)=alf0r(i).*cos(om(j)*t);
k1=8*II+2*a*cos(thi(i,j)).*(cos(Y(1))-Y(1)*sin(Y(1)));
dYdt=[Y(2);(1/k1)*((Y(2)).*(-2*B+theo(j).*(AR/AR+2).*b.*cos(thi(i,j)).*(-cos(Y(1)+Y(1).*sin(Y(1)))))+...
(Y(2).^2)*2*a*cos(thi(i,j))*(2*sin(Y(1))*Y(1)+Y(1)*cos(Y(1)))-Y(1)*C+...
theo(j)*(AR/AR+2)*e*(thi(i,j).*cos(thi(i,j))+(3/4-pic)*2*thi(i,j).*cos(thi(i,j)))+...
d*(thi(i,j)+(1/2-pic)*2*thi(i,j).*cos(thi(i,j)))-e*(1/pi)*sin(thi(i,j))*(CD0+1.6*(thi-atan(2*e*Y(2).*(cos(Y(1))-Y(1).*sin(Y(1))))).^2))];
end
end
function [Aout,Pstar] = processsignal(t,y)
% process signal
Y = y(:,1);
Ydot = y(:,2);
k = 2:length(Y)-1;
Kmax = find( Y(k)>Y(k-1) & Y(k)>Y(k+1) );
Kmax = Kmax+1; %correct index
Kmin = find( Y(k)<Y(k-1) & Y(k)<Y(k+1) );
Kmin = Kmin+1; %correct index
ti_max = 0.5*(t(Kmax(1:end-1))+t(Kmax(2:end)));
ti_min = 0.5*(t(Kmin(1:end-1))+t(Kmin(2:end)));
N = 5; % number of final cycles for averagingaw
Aout = 0.5*(mean(Y(Kmax(end-N,end))) - mean(Y(Kmin(end-N,end))));
subplot(2,1,1), plot(t,Y,t(Kmax),Y(Kmax),'ob',t(Kmin),Y(Kmin),'ob')
subplot(2,1,2), plot(t(Kmax),Y(Kmax),'o',t(Kmin),abs(Y(Kmin)),'o')
Jint = find(t>=t(Kmax(end-N)) & t<t(Kmax(end)));
Pstar = (1/4)*trapz(t(Jint),Ydot(Jint).^2); % integral,1/4
endIro Malefakihttps://kr.mathworks.com/matlabcentral/profile/authors/8512292-iro-malefaki