https://ww2.mathworks.cn/matlabcentral/answers/questionsMATLAB Answers — New Questions2020-11-30T04:57:50Ztag:ww2.mathworks.cn,2005:Question/6683982020-11-30T01:07:41Z2020-11-30T04:57:50ZHow Can I remove the Periodic Noise lines from Color image attached?Hy, I am trying to filter out the periodic lines in Colour image attached using FFT and IFFT and median filter. Can anybody help me in this please. The end result should be same colour picture but those grey lines gone or atlease faded away. Help will be appreciated
I am attaching the Picture and Code modified with the help of @Image Analyst.
% Demo to filter an image, with periodic ripple, in the Fourier domain.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 14;
%Read Image
grayImage = imread('Cereal_noise.png');
[rows, columns, numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
grayImage = rgb2gray(grayImage);
end
subplot(2, 3, 1);
imshow(grayImage, [0 255]);
title('Original Image', 'FontSize', fontSize);
set(gcf, 'units','normalized','outerposition',[0 0 1 1]); % Maximize figure.
% Compute the 2D fft.
frequencyImage = fftshift(fft2(grayImage));
% Take log magnitude so we can see it better in the display.
amplitudeImage = log(abs(frequencyImage));
minValue = min(min(amplitudeImage))
maxValue = max(max(amplitudeImage))
subplot(2, 3, 4);
imshow(amplitudeImage, []);
caption = sprintf('Notice the two spikes\nperpendicular to the periodic frequency');
title(caption, 'FontSize', fontSize);
axis on;
% zoom(10)
% Find the location of the big spikes.
amplitudeThreshold = 16;
brightSpikes = amplitudeImage > amplitudeThreshold; % Binary image.
subplot(2, 3, 5);
imshow(brightSpikes);
axis on;
title('Bright Spikes', 'FontSize', fontSize);
% Let user see the image.
promptMessage = sprintf('The image below shows the bright spikes.\nNow we will exclude the central spike.');
titleBarCaption = 'Continue?';
button = questdlg(promptMessage, titleBarCaption, 'Continue', 'Cancel', 'Continue');
if strcmpi(button, 'Cancel')
return;
end
% Exclude the central DC spike. Everything from row 115 to 143.
brightSpikes(115:143, :) = 0;
imshow(brightSpikes);
title('Bright spikes other than central spike', 'FontSize', fontSize);
promptMessage = sprintf('Now we will use these bright spikes to filter (mask) the spectrum.');
button = questdlg(promptMessage, titleBarCaption, 'Continue', 'Cancel', 'Continue');
if strcmpi(button, 'Cancel')
return;
end
% Filter/mask the spectrum.
frequencyImage(brightSpikes) = 0;
% Take log magnitude so we can see it better in the display.
amplitudeImage2 = log(abs(frequencyImage));
minValue = min(min(amplitudeImage2))
maxValue = max(max(amplitudeImage2))
subplot(2, 3, 5);
imshow(amplitudeImage2, [minValue maxValue]);
axis on;
title('Spikes zeroed out', 'FontSize', fontSize);
% zoom(10)
filteredImage = ifft2(fftshift(frequencyImage));
amplitudeImage3 = abs(filteredImage);
minValue = min(min(amplitudeImage3))
maxValue = max(max(amplitudeImage3))
subplot(2, 3, 6);
imshow(amplitudeImage3, [minValue maxValue]);
title('Filtered Image', 'FontSize', fontSize);
Zain ul abideen ahsanhttps://ww2.mathworks.cn/matlabcentral/profile/authors/10201542tag:ww2.mathworks.cn,2005:Question/6625732020-11-25T23:43:17Z2020-11-30T04:56:56ZSimple, but stumped. Using 'xline' to create animated "play marker" across waveform plot.I am trying to create a plot of a waveform that has a "play marker"/vertical line running across. Have been trying with 'xline' drawing at position 'ii' in a for loop, but I can't figure out how to clear previous lines, so every line position stays on the plot. (Have included test data lines at the top so it can run.)
I know the solution is bound to be really simple, but it eludes me. Currently investigating whether the 'animatedline' function call is better suited.
Many thanks for any help.
Cheers.
Fs = 48000;
Position01 = rand(Fs,11);
StartIndex = 1;
FinishIndex = 100;
figure;
subplot(2,1,1);
plot(Position01(StartIndex:FinishIndex,11));
hold on
title('test');
xlabel('test');
ylabel('test');
subplot(2,1,2);
plot(Position01(StartIndex:FinishIndex,1));
title('test');
xlabel('test');
ylabel('test');
for ii = 1 : length(Position01(StartIndex:FinishIndex,11))
xline(ii);
drawnow
endPeter Beringerhttps://ww2.mathworks.cn/matlabcentral/profile/authors/17669911tag:ww2.mathworks.cn,2005:Question/6684182020-11-30T01:23:01Z2020-11-30T04:56:54ZGaussian PDF from rayleighBy definition,
N(0,1) , w=sqrt(-2ln(1-R))*cos(2*pi*R+1)
w=gaussian pdf
R=uniform r.v
I tried to implement the above equation but it didn't work well.
L=sqrt(-2*log(1-R));
histogram(L)
P=cos(2*pi*R+1);
T=L.*P;
histogram(T)
R= uniform r.v
L= rayleigh pdf
T=gaussian pdf
rayleigh is good.
gaussian is weird,.,. :(jameskhttps://ww2.mathworks.cn/matlabcentral/profile/authors/19943424tag:ww2.mathworks.cn,2005:Question/6687182020-11-30T04:39:04Z2020-11-30T04:49:42ZThe way to make an array using function_hundle(関数ハンドルを用いた配列の作り方)関数ハンドルを用いた配列の作り方をご教授願いたいです。
例えば、
for i=1:5, f[i]=i.*x
としたときに
f[1]=x, f[2]=2.*x, f[3]=3.*x, f[4]=4.*x, f[5]=5.*x
といったデータが格納されるようなプログラムは可能しょうか？
ぜひよろしくお願いします。
I want the way to make an array using function_hundle.
For example, when I define
for i=1:5, f[i]=i.*x,
I wish to be stored
f[1]=x, f[2]=2.*x, f[3]=3.*x, f[4]=4.*x, f[5]=5.*x.
Please tell me the way...
Thank you.Yoshiki Satohttps://ww2.mathworks.cn/matlabcentral/profile/authors/16653589tag:ww2.mathworks.cn,2005:Question/6666032020-11-28T12:16:40Z2020-11-30T04:49:17ZSolving nonlinear equation using lsqnonlinHi
I am trying to solve a set of non-linear equations using lsqnonlin. Initially I was using 'levenberg-marquardt', but I was getting arbitrary results than what I was supposed to get. Then I tried solving using 'lsqnonlin' by defining some upper and lower bounds for the variables. However, the variables are now clinging to either the upper or the lower bound value. Therefore, the reults once again are not correct. What might be the reason for such behaviour?
Here is the code that I am using: (There are 36 to 56 variables. I am showing just 2 for example)
lb=[0.5,-0.5];
ub=[1.5,0.5];
x0=[1,0];
options=optimoptions(@lsqnonlin,'Algorithm','trust-region-reflective');
[x,res]=lsqnonlin(fun,x0,lb,ub,options);Anuj Kumar Sahoohttps://ww2.mathworks.cn/matlabcentral/profile/authors/15624209tag:ww2.mathworks.cn,2005:Question/6686082020-11-30T03:45:53Z2020-11-30T04:48:09ZHow to divide an image into regions or grids and then calculate the number of pixels in each grid or region? I have a binary image. I want to divide it into regions or grids and then calculate the number of pixels in each region. Can I do this without using ROI? Suyog Patharehttps://ww2.mathworks.cn/matlabcentral/profile/authors/10601536tag:ww2.mathworks.cn,2005:Question/6590832020-11-23T16:42:32Z2020-11-30T04:47:13ZHow to save different mat files from different folders in a cell array Hi friends,
I have 51 folders named with (copy_1, copy_2, copy_3 ..... copy_51). Each folder of these has 25 matfiles (X1, X2,X3...X25).
1- I want to concatenate all the matflies (25 matfiles) from each folder (51 folders) in cell array. The output cell will be (1275 * 1). I just want to save them like the attached picture.
i have tried this code, but it does not help me.
D = 'path to the folder where the files are saved'
S = dir(fullfile(D,'X*.mat'));
C = cell(1,numel(S));
Z = load(fullfile(D,S(1).name));
F = fieldnames(T);
for k = 2:numel(S)
T = load(fullfile(D,S(k).name));
for n = 1:numel(F)
Z.(F{n}) = cat(1, Z.(F{n}), T.(F{n}));
end
end
save(fullfile(D,'Y.mat'),'Z')
....
Any help will be highly appreciated .
Abdulhakim Alezzihttps://ww2.mathworks.cn/matlabcentral/profile/authors/8175745tag:ww2.mathworks.cn,2005:Question/6682932020-11-29T22:22:15Z2020-11-30T04:44:53ZHow to get all matrix values in 3X4 sub-matrix from an M x N matrix(Template Matching)Hi, I an fairly new to Matlab. I am doing template matching. What I want is to loop through the given image grascale matrix and get 3x4 matrix from that using a loop.
I have tried using nested for loops on rows and columns but handling that is becoming difficult as I also have to set some kind of outerbounds etc. I have also tried getting the 3x4 image using colon separator, but still Im stuck at how should my loop work to entertain all the values in the original image matrix. Any kind of help is appreciated. Thanks!Master Mhttps://ww2.mathworks.cn/matlabcentral/profile/authors/20487402tag:ww2.mathworks.cn,2005:Question/6687232020-11-30T04:41:35Z2020-11-30T04:44:23ZSignal segmentation in SimulinkHello,
How to segment an output signal (out1 of subsystem) into multiple segments (101 segments to match the Neural network input)? (where it is without exporting and importing to/from the workspace). Is there any block for signal segmentation?
Ahmed Alkimhttps://ww2.mathworks.cn/matlabcentral/profile/authors/20488950tag:ww2.mathworks.cn,2005:Question/6561482020-11-21T16:53:24Z2020-11-30T04:43:23ZHow do i replace Euler's method with ode45?Hi, I'm trying to replace the Section of the code that uses Euler's methos to solve the ode by ode45,
and i have the individual codes, but i'm unsure how to insert one into another:
First, I have my main code, which uses Euler's method to solve the ode( TBH, i'm not sure if it even solves an ode, because there isn't
an explicitly defined ode in the code, more like a rotation matrix, but it gives me the output of an oscillating pendulum)
(Basically, i do not understand how the motion of the pendulum is plotted using a rotation matrix)
function Animation
% A script to animate the motion of the simple pendulum
clc
clear
close all;
disp('Specify the initial angle of the pendulum in degrees, e.g., 50')
disp('or press ENTER for the default value.')
theta=input('Initial angular displacement of the pendulum= ');
if isempty(theta)
theta=50
else
theta;
end
theta=theta*pi/180; % convert from degrees to radians
disp('Specify the final time, e.g. tfinal = 25')
disp('or press ENTER for default value.')
tfinal=input('Final time tfinal = ');
if isempty(tfinal)
tfinal=10
else
tfinal;
end
data_init=[0 0; -4 0]; %pendulum length
% rotation matrix
R=[cos(theta) -sin(theta);sin(theta) cos(theta)];
data=R*data_init; % initial pendulum position
bar=line('xdata',[0 data(1)],'ydata',...
[0 data(2)]','linewidth',3);
mass=line('xdata',data(1),'ydata',data(2),'marker','o',...
'markersize',15,'MarkerFaceColor','b');
hinge=line('xdata',0,'ydata',0,'marker','o',...
'markersize',7);
axis([-5 5 -5 5])
grid % comment this out if you do like the grid
set(gca,'Fontsize',14)
set(gca,'dataaspectratio',[1 1 1])
box on
dt=0.03; % step−size for solving differential
% equations can be arbitrarily selected
t=0; % initial time
thetadot=0; % initial angular speed
disp('Can maximize the display so you can see the action better,')
disp('then press ENTER.')
disp('If you are happy with the display size, press ENTER.')
pause
v = VideoWriter('pendulum4.avi');
open(v);
% solve the diff eqns using the Euler's method
while(t<tfinal)
t=t+dt;
theta = theta + thetadot*dt;
thetadot=thetadot - 5*sin(theta)*dt; %−0.01*thetadot;
% you can add some friction
R=[cos(theta) -sin(theta);sin(theta) cos(theta)];
datanew=R*data_init;
% change the property values of the bar and hinge objects
set(bar,'xdata',[0 datanew(1)],'ydata',[0 datanew(2)]);
set(mass,'xdata',datanew(1),'ydata',datanew(2));
set(hinge,'xdata',0,'ydata',0)
set(gca,'dataaspectratio',[1 1 1])
drawnow;
% get the frame and write to the file
frame = getframe(gcf);
writeVideo(v,frame);
end
% close the video writer
close(v);
end
Next, I have my code which uses ode45 to solve the equation of motion of the pendulum, which solves both the linear and nonlinear equations of motion using two functions, pend_l ( for linear) and pend_n ( for nonlinear)
clear all;
clc;
clf;
tic;
tspan = 0:0.01:20;
a=pi/8;
b=0;
x0 = [a; b];
[t1,x] = ode45(@pend_l,tspan,x0);
X1 = x(:,1);
X2 = x(:,2);
y0 = [a ; b];
[t2,y] = ode45(@pend_n,tspan,y0);
Y1 = y(:,1);
Y2 = y(:,2);
%figure(1);
subplot(2,2,1);
plot(t1,X1); %linear disp vs time
xlabel('Time (s)');
ylabel('Displacement (rad)');
hold on;
grid on;
plot(t2,Y1); %nonlinear disp vs time
legend('Linear','Non Linear');
%figure(2);
subplot(2,2,2);
plot(t1,X2); %linear velocity vs time
xlabel('Time (s)');
ylabel('Velocity (rad/s)');
hold on;
grid on;
plot(t2,Y2); %nonlinear velocity vs time
subplot(2,2,3);
plot(X1,X2); %linear vel vs disp
hold on;
plot(Y1,Y2); %nonlinear vel vs disp
xlabel('Displacement (rad)');
ylabel('Velocity (rad/s)');
grid on;
toc;
function ydot = pend_n(t2,y)
wsq=3.5; % same value of wsq in both cases is required
ydot = [y(2); -wsq*sin(y(1))];
end
function xdot = pend_l(t1,x)
wsq=3.5;
xdot = [x(2); -wsq*x(1)];
endKLETECH MOTORSPORTShttps://ww2.mathworks.cn/matlabcentral/profile/authors/14138993tag:ww2.mathworks.cn,2005:Question/6687032020-11-30T04:13:09Z2020-11-30T04:40:42ZDetecting coordinates of line edges
I have a matrix containing 1s and 0s. The elements of this matrix are pixels of an image, where 1&0 represents black and white . The 1s form non-intersecting line segmennts.
I wanted to know pixel coordinates of line edges.
Following is an example matrix-
A= [0 1 0 0;...
0 0 1 0; ...
0 0 0 1; ...
0 0 0 0]
The outout: [1 2], [3 4]
Note that there could be multiple line segments.
Is Hough transform useful here?
ThanksPankajhttps://ww2.mathworks.cn/matlabcentral/profile/authors/5953919tag:ww2.mathworks.cn,2005:Question/6687082020-11-30T04:27:25Z2020-11-30T04:39:07ZReinforcement learning toolbox error when using SimscapeI get this error when I attempt to train the RL agent using a simulated refrigeration cycle environment.
Warning: Error occurred while executing the listener callback for event EpisodeFinished defined for class rl.env.SimulinkEnvWithAgent:
Error using rl.policy.AbstractPolicy/getAction (line 258)
Invalid observation type or size.
Error in rl.agent.rlDDPGAgent/evaluateQ0Impl (line 141)
action = getAction(this, observation);
Error in rl.agent.AbstractAgent/evaluateQ0 (line 275)
q0 = evaluateQ0Impl(this,observation);
Error in rl.train.TrainingManager/update (line 134)
q0 = evaluateQ0(this.Agents(idx),epinfo(idx).InitialObservation);
Error in rl.train.TrainingManager>@(info)update(this,info) (line 437)
trainer.FinishedEpisodeFcn = @(info) update(this,info);
Error in rl.train.Trainer/notifyEpisodeFinishedAndCheckStopTrain (line 56)
stopTraining = this.FinishedEpisodeFcn(info);
Error in rl.train.SeriesTrainer>iUpdateEpisodeFinished (line 31)
notifyEpisodeFinishedAndCheckStopTrain(this,ed.Data);
Error in rl.train.SeriesTrainer>@(src,ed)iUpdateEpisodeFinished(this,ed) (line 17)
@(src,ed) iUpdateEpisodeFinished(this,ed));
Error in rl.env.AbstractEnv/notifyEpisodeFinished (line 324)
notify(this,'EpisodeFinished',ed);
Error in rl.env.SimulinkEnvWithAgent/executeSimsWrapper/nestedSimFinishedBC (line 222)
notifyEpisodeFinished(this,...
Error in rl.env.SimulinkEnvWithAgent>@(src,ed)nestedSimFinishedBC(ed) (line 232)
simlist(1) = event.listener(this.SimMgr,'SimulationFinished' ,@(src,ed) nestedSimFinishedBC(ed));
Error in Simulink.SimulationManager/handleSimulationOutputAvailable
Error in Simulink.SimulationManager>@(varargin)obj.handleSimulationOutputAvailable(varargin{:})
Error in MultiSim.internal.SimulationRunnerSerial/executeImplSingle
Error in MultiSim.internal.SimulationRunnerSerial/executeImpl
Error in Simulink.SimulationManager/executeSims
Error in Simulink.SimulationManagerEngine/executeSims
Error in rl.env.SimulinkEnvWithAgent/executeSimsWrapper (line 244)
executeSims(this.SimEngine,simfh,in);
Error in rl.env.SimulinkEnvWithAgent/simWrapper (line 267)
simouts = executeSimsWrapper(this,in,simfh,simouts,opts);
Error in rl.env.SimulinkEnvWithAgent/simWithPolicyImpl (line 424)
simouts = simWrapper(env,policy,simData,in,opts);
Error in rl.env.AbstractEnv/simWithPolicy (line 82)
[experiences,varargout{1:(nargout-1)}] = simWithPolicyImpl(this,policy,opts,varargin{:});
Error in rl.task.SeriesTrainTask/runImpl (line 33)
[varargout{1},varargout{2}] = simWithPolicy(this.Env,this.Agent,simOpts);
Error in rl.task.Task/run (line 21)
[varargout{1:nargout}] = runImpl(this);
Error in rl.task.TaskSpec/internal_run (line 166)
[varargout{1:nargout}] = run(task);
Error in rl.task.TaskSpec/runDirect (line 170)
[this.Outputs{1:getNumOutputs(this)}] = internal_run(this);
Error in rl.task.TaskSpec/runScalarTask (line 194)
runDirect(this);
Error in rl.task.TaskSpec/run (line 69)
runScalarTask(task);
Error in rl.train.SeriesTrainer/run (line 24)
run(seriestaskspec);
Error in rl.train.TrainingManager/train (line 421)
run(trainer);
Error in rl.train.TrainingManager/run (line 211)
train(this);
Error in rl.agent.AbstractAgent/train (line 78)
TrainingStatistics = run(trainMgr);
Error in starter_script (line 214)
trainingStats = train(agent,env,trainOpts);
Caused by:
Error using rl.representation.rlAbstractRepresentation/validateInputData (line 525)
Input data dimensions must match the dimensions specified in the corresponding observation and action info specifications.
> In rl.env/AbstractEnv/notifyEpisodeFinished (line 324)
In rl.env.SimulinkEnvWithAgent.executeSimsWrapper/nestedSimFinishedBC (line 222)
In rl.env.SimulinkEnvWithAgent>@(src,ed)nestedSimFinishedBC(ed) (line 232)
In Simulink/SimulationManager/handleSimulationOutputAvailable
In Simulink.SimulationManager>@(varargin)obj.handleSimulationOutputAvailable(varargin{:})
In MultiSim.internal/SimulationRunnerSerial/executeImplSingle
In MultiSim.internal/SimulationRunnerSerial/executeImpl
In Simulink/SimulationManager/executeSims
In Simulink/SimulationManagerEngine/executeSims
In rl.env/SimulinkEnvWithAgent/executeSimsWrapper (line 244)
In rl.env/SimulinkEnvWithAgent/simWrapper (line 267)
In rl.env/SimulinkEnvWithAgent/simWithPolicyImpl (line 424)
In rl.env/AbstractEnv/simWithPolicy (line 82)
In rl.task/SeriesTrainTask/runImpl (line 33)
In rl.task/Task/run (line 21)
In rl.task/TaskSpec/internal_run (line 166)
In rl.task/TaskSpec/runDirect (line 170)
In rl.task/TaskSpec/runScalarTask (line 194)
In rl.task/TaskSpec/run (line 69)
In rl.train/SeriesTrainer/run (line 24)
In rl.train/TrainingManager/train (line 421)
In rl.train/TrainingManager/run (line 211)
In rl.agent.AbstractAgent/train (line 78)
In starter_script (line 214)
When I checked the inputs to the reward, isdone, and observation ports, it showed that I have input them correctly. The image below shows the outputs of the reward, isdone, and observation outputs when it was tested with fixed action values. There are 2 actions.
Any ideas on what could be causing this issue? I checked the other relevant answers and could not pinpoint my issue. The issue also occur regardless of whether I am using gpu or cpu.
Compared to the example, a major difference is that I have used many goto and from blocks in the model for simplicity as shown in the figure below. The delay blocks are used to break algebraic loops.
Thank you very much!
Tech Logg Dinghttps://ww2.mathworks.cn/matlabcentral/profile/authors/12339622tag:ww2.mathworks.cn,2005:Question/6679582020-11-29T14:41:41Z2020-11-30T04:38:51Zhow to use if comparison my problem is i want to compare like the code below and if the condition is met i want it to keep its current value but if the condition is not met iwant to change the value into 0 but when i run the code all the value turn to zero. Can you correct my code?
for c=2:length(fbtbopfin)
for d=1:length(fbtbopfin)
if fbtbopfin(c,1)==fbtbopfin(d,2)
fbtbopfin(c,1)=fbtbopfin(c,1);
else fbtbopfin(c,1)=0;
end
end
end
here is the fbtbopfin matrix
1 2
2 3
3 4
4 5
5 6
6 7
7 8
0 0
10 11
11 12
12 13
13 14
15 16
16 17
17 18
2 19
19 20
20 21
21 22
3 23
23 24
24 25
6 26
26 27
27 28
29 30
30 31
31 32
9 15
12 22
18 33
25 29Enda Sembiringhttps://ww2.mathworks.cn/matlabcentral/profile/authors/19007044tag:ww2.mathworks.cn,2005:Question/6687132020-11-30T04:31:38Z2020-11-30T04:37:05ZNeed help on array multiplicationI need help with the following
u1=[2 3 1 0];
u2=[2 1 3 0];
u3=[2 3 1 3];
u=[u1 u2 u3];
v1=mod(u1+u3,4)=[0 2 2 3]
v2=mod(u1+u2+u3,4)=[2 3 1 3]
v3=u3=[2 3 1 3]
v4=mod(u2+u3,4)=[0 0 0 3]
GRL=[1 1 0 0;0 1 0 1;1 1 1 1];
How can I use the multiplication similar to v=u*GRL to obtain the above results?
Ronald Niwamanyahttps://ww2.mathworks.cn/matlabcentral/profile/authors/19345836tag:ww2.mathworks.cn,2005:Question/6683682020-11-30T00:08:43Z2020-11-30T04:30:43Z3D Printer CostsCould I get some help with a code for 3D printing costs?
I'm not good at this, but want to use MATLAB for my job on quoting 3D printing jobs.
I have a few perimeters to go off of and anything else that is needed I can provide.
Cost per roll of filament is $20.32 and has roughly 322 meters per roll.
9.3 cents per kWh of power consumption. It uses 240 watts while running.
The print takes 1hr and 45 minutes and the volume is 3.848 inches cubed.
I will use 10% infill for this particular part.
I'm not sure where to start, but have some experience with MATLAB. I just want it done the easy way so I can use it for quoting jobs. LD1690https://ww2.mathworks.cn/matlabcentral/profile/authors/19293729tag:ww2.mathworks.cn,2005:Question/6686932020-11-30T04:04:40Z2020-11-30T04:28:06ZHow do I print the final value of RMSE on the command line?I am trying to denoise using deep learning based on the following.
https://jp.mathworks.com/help/audio/ug/denoise-speech-using-deep-learning-networks.html
How do I print the final value of RMSE on the command line?若菜 中井https://ww2.mathworks.cn/matlabcentral/profile/authors/20025963tag:ww2.mathworks.cn,2005:Question/6683782020-11-30T00:23:13Z2020-11-30T04:28:01ZError using optimset(@lsqnonlin) matlab 2020bHi,
I'm having trouble using optimset () for lsqnonlin () function. I am using matlab version 2020b.
...
options = optimset(@lsqnonlin)
X = lsqnonlin('filtroRC', X0, [], [], options, Vin, t, Vout_e)
...
Error using optimset (line 163)
No default options available for the function 'lsqnonlin'.
I would appreciate suggestionsJuan Gómezhttps://ww2.mathworks.cn/matlabcentral/profile/authors/19324797tag:ww2.mathworks.cn,2005:Question/6484182020-11-15T09:32:19Z2020-11-30T04:27:58Zcontour plot of a 3D Solid ObjectI imported the .stl file like this
fv = stlread('EXAMPLE.stl');
patch(fv,'FaceColor', [0.8 0.8 1.0], ...
'EdgeColor', 'none', ...
'FaceLighting', 'gouraud', ...
'AmbientStrength', 0.15);
grid off
hold on
axis equal
But I can't create the outline of the solid object. Anyone know how I can do?
For example the sphere in the figure
Alberto Acrihttps://ww2.mathworks.cn/matlabcentral/profile/authors/12366813tag:ww2.mathworks.cn,2005:Question/6592632020-11-23T19:11:43Z2020-11-30T04:21:53ZMatlab livescript tab sizeI would like to know how one can set the tab and indent size of livescript. I see
https://www.mathworks.com/matlabcentral/answers/475505-why-does-indent-in-live-scripts-not-obey-indent-setting
I would like to know whether there is an update on this issue. alpedhuezhttps://ww2.mathworks.cn/matlabcentral/profile/authors/10930090tag:ww2.mathworks.cn,2005:Question/4513832019-03-21T10:56:41Z2020-11-30T04:16:48ZIssue with batch normalization layer of saved CNNWhen loading a previously trained CNN, I got an issue with the batch normalization layers. When looking into the loaded CNN model the trainable mean and variance are empty.
Name: 'batchnorm_1'
TrainedMean: []
TrainedVariance: []
So the checkpoint doesn't seem to save these parameters. Are there any workarounds for this issue? I am using Matlab R2018b.Kjetil Kveimhttps://ww2.mathworks.cn/matlabcentral/profile/authors/14594950tag:ww2.mathworks.cn,2005:Question/6419252020-11-09T05:00:00Z2020-11-30T04:09:14ZIs MATLAB supported on Apple Silicon Macs?Macs with an Apple silicon processor such as the Apple M1 have two ways to run applications. Applications built for Apple silicon run natively, while apps built for Intel processors run in the Rosetta 2 environment. Which method does MATLAB support? MathWorks Support Teamhttps://ww2.mathworks.cn/matlabcentral/profile/authors/4622813tag:ww2.mathworks.cn,2005:Question/6549432020-11-20T17:07:54Z2020-11-30T04:06:46ZHow to write code for a composite signal with instantaneous frequencyAnyone can help me with writing code for this function?
Jan Alihttps://ww2.mathworks.cn/matlabcentral/profile/authors/17449316tag:ww2.mathworks.cn,2005:Question/6684832020-11-30T03:19:01Z2020-11-30T04:05:36Z Is it normal to stop and save a network for more than 14 hours?
I saved my network using the following function when it completed training progress（Fig.1）. But after more than 14 hours, the network still has not finished saving process. The GPU has always been running during the saving process (Fig.2).
net = trainNetwork(trainData,lgraph,options);
save([dir,'Anet'],'net','-v7.3')
Fig. 1
Fig. 2Yi Weihttps://ww2.mathworks.cn/matlabcentral/profile/authors/17062322tag:ww2.mathworks.cn,2005:Question/6686982020-11-30T04:04:59Z2020-11-30T04:04:59ZInstrument interface using matlabHi,
I am new to matlab. may be the question I am going to ask is just simple one, still please answer as well as suggest me somthing else also wich might needed me in future for instrument interface programming.
I am Trying to connect my Kyithley Nanovolmeter to my computer using NI 488.2 GPIB to USB connector. what type of driver i need ti install ? where i will get this ? do i need to install driver seperately for GPIB and My instrument ?(if this is the case then I have KUSB 488 GPIB-usb connector with me, shall I preffer that one over the Ni?). and if some one have sample code written for any of their instrument please send me that also!
Thank you in advance!!
kindly,
SomnathSomnath Kalehttps://ww2.mathworks.cn/matlabcentral/profile/authors/19995451tag:ww2.mathworks.cn,2005:Question/6682732020-11-29T21:37:09Z2020-11-30T04:03:21ZIntersection of two vector of string/char typeHi.What is an analogue function for "intersect" when the vectors have string entries? For example A(1)='EDP PL',A(2)='VOD LN'. B(1)='VOD LN',B(2)='BNPP FP'.
If I have tow numerical vectors v1 and v2 I can find the intersection and the positions by simply [ig,ind1,ind2]=intersect(v1,v2).
How do I deal with this kind of situation ?Mihai Mileahttps://ww2.mathworks.cn/matlabcentral/profile/authors/19575961tag:ww2.mathworks.cn,2005:Question/6642082020-11-27T01:36:44Z2020-11-30T03:55:50Zhow to judge a array is dlarray in matlab?how to judge a array is dlarray in matlab? If it is a dlarray type, so I can perform an extractdata operationcuihttps://ww2.mathworks.cn/matlabcentral/profile/authors/3388605tag:ww2.mathworks.cn,2005:Question/6683832020-11-30T00:36:19Z2020-11-30T03:55:04ZRecombine cell arrays to produce a new imageHi, I've split an image into blocks
for testing ive skipped all odd blocks
now how to i recombine all cells to create the a new picture with all the cells
plotIndex = 1;
numPlotsR = size(Cellarray, 1);
numPlotsC = size(Cellarray, 2);
for r = 1 : numPlotsR
for c = 1 : numPlotsC
if bitget(c,1)
fprintf('plotindex = %d, c=%d, r=%d\n', plotIndex, c, r);
else
fprintf('noooooo\n')
end
% Plot consecutively.
if bitget(c,1)
subplot(numPlotsR, numPlotsC, plotIndex);
plotIndex = plotIndex +1
continue;
end
% Extract the numerical array out of the cell
rgbBlock = Cellarray{r,c};
imshow(rgbBlock); % Could call imshow(ca{r,c})
[rowsB, columnsB, numberOfColorBandsB] = size(rgbBlock);
caption = sprintf('B#%d/%d', ...
plotIndex, numPlotsR*numPlotsC);
title(caption);
drawnow;
% Increment the subplot to the next location.
plotIndex = plotIndex + 1;
end
end
Saud Alfalasihttps://ww2.mathworks.cn/matlabcentral/profile/authors/14898575tag:ww2.mathworks.cn,2005:Question/6599882020-11-24T07:48:43Z2020-11-30T03:54:15ZCalculating integration limits of a double integralHello,
I am working on a college assignment to calculate the symbolical value and the numerical approximation of the double integral of over the region defined by and to determine the integration limits in y by symbolical computation.
Unfortunately, I haven't been able to figure out how to calculate the integration limits without knowing the final result. Sorry if this is easy, but I am a beginner in Matlab and my knowledge of double integrals isn't very profound.
Could someone please give me a hint how to solve this problem?
Thank You.mj702https://ww2.mathworks.cn/matlabcentral/profile/authors/15589009tag:ww2.mathworks.cn,2005:Question/6454832020-11-12T10:05:07Z2020-11-30T03:51:30ZGPU Code generation for 'vehicle detector yolov2' in matlab2020aHi,
I was trying to generate GPU cuda code for my program using matlab2020a. Am using detector 'vehicleDetectorYOLOv2()' for generating the vehicle detections and then using another neural network (network generated using 'patternnet') for color detection of detected vehicles.
is there any way I can generate GPU cuda code for vehicleDetectorYOLOv2() & neural network generated using patternnet using GPU coder?
I have found one link: https://in.mathworks.com/help/gpucoder/ug/code-generation-for-object-detection-using-YOLOv2.html. Could someone please suggest whether I should follow the same steps for 'vehicleDetectorYOLOv2()'?
Also any useful information regarding gpu code generation for 'neural network (network generated using 'patternnet')' also most welcome.
Am planning to use the generated CUDA code on a windows machine with installed NVIDIA GPU. any suggestions / adviceor usefull links on this?Nithin Mhttps://ww2.mathworks.cn/matlabcentral/profile/authors/11058888tag:ww2.mathworks.cn,2005:Question/6643632020-11-27T03:06:16Z2020-11-30T03:48:35ZHow to deleted Enter chara = '
'MOVABLE,ERASABLE,
MERGEABLE'
a(18) = '
' % there hava a Enter char
I want to delete the Enter Char.
the way ('\n' or 'r' or '\r\n' ) is error. so how to delete the Enter charwangxiaoninghttps://ww2.mathworks.cn/matlabcentral/profile/authors/11847610tag:ww2.mathworks.cn,2005:Question/6683932020-11-30T00:47:29Z2020-11-30T03:39:56ZCell Array Search and indexingHello,
Please how do I find the maximum column in a cell array and assign the index position to other variables?
i = 1:5
j = 1:8
AllOutput{1,i}{1,j};
max([AllOutput{1,i}{1,2}],[],2) % Tried this but cannot seem to get it to work through all the i matrix
DT_values = AllOutput{1,i}{1,2}; % find the maximum column from all the ith array
maximum = ((max(DT_values,[],2)));
[M,I]=find(DT_values==maximum);
Dr_opt = AllOutput{1,i}{1,3};
Output= Dr_opt(I); %Assign other variables to the same index position as aboveZaharaddeen Hussainihttps://ww2.mathworks.cn/matlabcentral/profile/authors/5316598tag:ww2.mathworks.cn,2005:Question/6682832020-11-29T21:55:36Z2020-11-30T03:38:33ZHow can I stop my program and ask for the wish operation?Hello everyone, I have this program who ask for rows of matrix and columns. My problem is that once I have already asked for columns and rows of matrix A and B I need to ask what operation the person wants to do. For example. I need to ask "Selesct pointwise operation of matrices A and B: 1: Multiplication 2:Division 3:Exponential.
However my program realize the mutiplication and division by itself and I need to stop it and ask first.
disp(' ');
switch_1=1;
while switch_1==1
rows_matrix_A=input('Enter the rows of Matrix A => ');
columns_matrix_A=input('Enter the columns of Matrix A => ');
rows_matrix_B=input('Enter the rows of Matrix B => ');
columns_matrix_B=input('Enter the columns of Matrix B => ');
disp(' ')
if columns_matrix_A==rows_matrix_B
for i=1:rows_matrix_A
for j=1:columns_matrix_A
A(i,j)=input('Enter element of matrix A => ');
end
end
disp(' ')
for i=1:rows_matrix_B
for j=1:columns_matrix_B
B(i,j)=input('Enter element of matrix B => ');
end
end
disp(' ')
disp('Matrix A: ')
disp(A)
disp(' ')
disp('Matrix B: ')
disp(B)
C=A*B;
disp(' ')
disp('Matrix C: ')
disp(C)
D=A/B;
disp(' ')
disp('Matrix C: ')
disp(D)
else
disp('Error, Standard multiplication cannot be perfomed! ')
disp(' ')
end
switch_1=input('DO you want to run the program again? 1=YES 2=NO ');
disp(' ')
endJohan De Graciahttps://ww2.mathworks.cn/matlabcentral/profile/authors/19285419tag:ww2.mathworks.cn,2005:Question/6684382020-11-30T02:44:17Z2020-11-30T03:33:43ZHow can I include an equation in a scatter plot with linear regression line? Part 2https://www.mathworks.com/matlabcentral/answers/64754-how-can-i-include-an-equation-in-a-scatter-plot-with-linear-regression-line
shows how to add a linear regression equation to the scatter plot.
Is it possible to add Rsquared and t-statics? (I am not sure whether I can get them as an output of polyfit.)alpedhuezhttps://ww2.mathworks.cn/matlabcentral/profile/authors/10930090tag:ww2.mathworks.cn,2005:Question/6681982020-11-29T19:56:33Z2020-11-30T03:33:07ZHow do I continue to read files in a loop when an error occurs?Hello, I am trying to read .FIT files provided by my teacher and when reading the last bunch of them an error occurs. I tried using a try catch to continue, and it skips over and continues the loop, but I am not getting my value D.
Error using fitsinfo>openFile (line 760)
Unable to open file. File might be corrupt or filename might have unsupported characters.
for l = 100:999
try
fit2file = sprintf('x.000000%d.FIT',l);
D = fitsread(fit2file);
catch
end
end
Thank you in advanceCeleste Collurahttps://ww2.mathworks.cn/matlabcentral/profile/authors/10934502tag:ww2.mathworks.cn,2005:Question/6684232020-11-30T01:59:51Z2020-11-30T03:33:03ZSimpson's 1/3 Rule if mod(n,2) == 1
disp('Simpsons Rule cannot be applied when an odd number of intervals is chosen')
return
else
int = (n-2)/2;
Coefficients = [1, repmat([4 2],1,int),4,1];
end
I am using the loop above to create the coefficents required to apply Simpson's 1/3 rule but I keep getting an error at the end of my code that says," Unable to perform assignment because the left and right sides have a different number of elements." I feel that the error is caused by the repmat statement which is creating a row vector that is too large. My output vector is supposed to have 5 values if this helps. Let me know if you need additional information and thank you in advance!!Jack Harkerhttps://ww2.mathworks.cn/matlabcentral/profile/authors/13390453tag:ww2.mathworks.cn,2005:Question/1396462014-07-01T07:48:21Z2020-11-30T03:31:24ZTable comparing Session Based Interface and Legacy Interface on daq toolboxIs there a complete list of daq commands that shows the Session-based command for corresponding Legacy Interface ? For example, 'daqhwinfo' there is a small grey box note that says:
_"Note: You cannot use the legacy interface on 64–bit MATLAB. See Using the Session-Based Interface to acquire and generate data."_
It would be nice if this links to corresponding Session-based command instead of leaving us trying to figure it out. Very annoying.
Does such a list exist where I can search for legacy command and find corresponding session-based command ? Rabindrahttps://ww2.mathworks.cn/matlabcentral/profile/authors/1121447tag:ww2.mathworks.cn,2005:Question/960052012-02-27T22:41:00Z2020-11-30T03:28:22ZWhy do I get the error "Undefined function or variable"?I am receiving the following error message, how can I resolve this issue?
ERROR: ??? Undefined function or variable ‹FunctionName›
??? Undefined function or method ‹FunctionName› for input arguments of type ‹ClassName›.
MathWorks Support Teamhttps://ww2.mathworks.cn/matlabcentral/profile/authors/4622813tag:ww2.mathworks.cn,2005:Question/6655832020-11-27T20:01:05Z2020-11-30T03:20:28ZChoose Lyapunov function of a linear systemHello everyone,
I would like to perform the Lyapunov stability of the following linear system. It is the linearization of a quite complex nonlinear system around the equilibrium in the origin. The Jacobian matrix (A below) has a null eigenvalue, so I can't say anything about the stability of the equilibrium point.
The equilibrium point is .
In matrix form it is like: , where and
A = 0 0 0 1 0 0
0 0 0 0 1 0
0 0 0 0 0 1
-c c 0 -b 0 0
0 -c c 0 -b 0
c 0 -c 0 0 -b
and are positive numbers.
I would like to perform the Lyapunov stability, but I'm not sure about the kind of Lyapunov function to select. I tried to employ quadratic functions where all the state variables are squared and summed together, everyone with its own parameter, but it doesn't seem a good idea. I tried also to have other quadratic functions combining the state variables in a more complex way, but it didn't work.
Does anyone have any idea? Just about the kind of function to select. I keep on trying...
Thank you very much in advanceCristina Magnetti Gisolohttps://ww2.mathworks.cn/matlabcentral/profile/authors/8840180tag:ww2.mathworks.cn,2005:Question/5910012020-09-09T08:33:39Z2020-11-30T03:10:54ZHow to export Simulink model to win32 standalone FMU?I'm using the Simulink Compiler to export Simulink Model to fmu, following this instruction:
Export Simulink Model to Standalone FMU: https://www.mathworks.com/help/slcompiler/ug/_mw_a294b424-4e58-4420-bfc9-0c37d1a66680.html
My SW setup is as followed:
Matlab R2020a
Visual Studio 2019 Community
Visual Studio 2017 Community
MinGW-w64 (installed through Add-on Explorer)
The fmu I got only contains win64 binaries. How can I generate the win32 binaries?Yongtao Tanhttps://ww2.mathworks.cn/matlabcentral/profile/authors/11491284tag:ww2.mathworks.cn,2005:Question/6684432020-11-30T03:05:57Z2020-11-30T03:05:57Z Problem using a resource in two activitiesWe have an operator that performs two activities without any priority. What happens to me is that when modeling it I notice that the operator only operates one line without reaching the other.In the following image you can see how it is model. Thanks a lot
Laura Margarita Prada Mejíahttps://ww2.mathworks.cn/matlabcentral/profile/authors/20397509tag:ww2.mathworks.cn,2005:Question/6608982020-11-24T20:22:51Z2020-11-30T02:50:04Zsendmail does not work on Matlab onlineIs there an alternative function for sendmail in matlab online.Juan Quezadahttps://ww2.mathworks.cn/matlabcentral/profile/authors/14243609tag:ww2.mathworks.cn,2005:Question/6288332020-10-28T09:00:08Z2020-11-30T02:48:34Zmatlab install and launch problem I installed MATLAB R2020b from my college USTC distribution with key and lic on the servers in my lab.
I succeed install it in one server while the other two failed.
The failed message is
"glibc_shim: Didn't find correct code to patch"
it shows before I tried to install it and when I launch it(I used install-unix-legacy in the bin/glnxa64 path to install when the default one didn'r work), it shows no matter I disable opengl or display. Nothing comes out after this message. This message repeated twice on the 3rd machine metioned below and once on the 2nd machine.
I think it's perhaps due to the linux version problem.
the success one's linux version is
Linux version 3.10.0-1127.19.1.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) ) #1 SMP
CentOS Linux release 7.8.2003 (Core)
the failed two are
Linux version 3.10.0-327.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.3 20140911 (Red Hat 4.8.3-9) (GCC) ) #1
CentOS Linux release 7.2.1511 (Core)
Linux version 2.6.32-754.11.1.el6.x86_64 (mockbuild@x86-01.bsys.centos.org) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC) ) #1 SMP
CentOS release 6.10 (Final)
The system requirement for R2020b is above RedHat 6. Considering the version of GCC and I think the 3rd one is Red Hat 6 and the former two are Red hat 7. Google this message gives nothing useful. And thus I have to ask here to see if anyone has the same problem.
lin shengfuhttps://ww2.mathworks.cn/matlabcentral/profile/authors/4404965tag:ww2.mathworks.cn,2005:Question/6630182020-11-26T06:10:22Z2020-11-30T02:45:34Z Error using rl.env.SimulinkEnvWithAgent>localHandleSimoutErrors (line 689) (By RL toolbox)I want to creat the multi-discrete actor outputs.
It will be like delta1 output 1 or 0, and delta2 is the same.
but there comes the error
Error using rl.env.AbstractEnv/simWithPolicy (line 70)
An error occurred while simulating "quarter_car" with the agent "agent".
Error using rl.env.SimulinkEnvWithAgent>localHandleSimoutErrors (line 689)
Invalid input argument type or size such as observation, reward, isdone or loggedSignals.
Error using rl.env.SimulinkEnvWithAgent>localHandleSimoutErrors (line 689)
Unable to evaluate representation.
Error using rl.env.SimulinkEnvWithAgent>localHandleSimoutErrors (line 689)
The logical indices contain a true value outside of the array bounds.
I don't understand the error is cause by the code or the simulink, and how to fix it.
% create observation info
observationInfo = rlNumericSpec([numObs 1],'LowerLimit',-inf*ones(numObs,1),'UpperLimit',inf*ones(numObs,1));
observationInfo.Name = 'observation';
% create action Info
actionInfo = rlFiniteSetSpec({[0;0],[1;1]});
actionInfo.Name = 'actor';
% define environment
env = rlSimulinkEnv(mdl,agentblk,observationInfo,actionInfo);
rng(0)
actorNetwork = [
imageInputLayer([numObs 1 1],'Normalization','none','Name','observation')
fullyConnectedLayer(200,'Name','ActorFC1')
reluLayer('Name','ActorRelu1')
fullyConnectedLayer(150,'Name','ActorFC2')
reluLayer('Name','ActorRelu2')
fullyConnectedLayer(numAct,'Name','ActorFC3')
tanhLayer('Name','ActorTanh')];
actorOpts = rlRepresentationOptions('LearnRate',1e-3,'GradientThreshold',1);
actor= rlStochasticActorRepresentation(actorNetwork, obsInfo, actInfo, 'Observation', {'observation'}, actorOpts);
agentOpts = rlPPOAgentOptions(...
'ExperienceHorizon',600,...
'ClipFactor',0.02,...
'EntropyLossWeight',0.01,...
'MiniBatchSize',128,...
'NumEpoch',3,...
'AdvantageEstimateMethod','gae',...
'GAEFactor',0.95,...
'SampleTime',h,...
'DiscountFactor',0.997);
agent = rlPPOAgent(actor,critic,agentOpts);
Hong-Ruei Ciouhttps://ww2.mathworks.cn/matlabcentral/profile/authors/9506493tag:ww2.mathworks.cn,2005:Question/4762542019-08-15T12:10:46Z2020-11-30T02:43:58ZI can't match correct code .. any help ?? Write a function called taxi_fare that computes the fare of a taxi ride. It takes two inputs: the distance in kilometers (d) and the amount of wait time in minutes (t). The fare is calculated like this:
the first km is $5
every additional km is $2
and every minute of waiting is $0.25.
Once a km is started, it counts as a whole (Hint: consider the ceil built-in function). The same rule applies to wait times. You can assume that d >0 and t >= 0 but they are not necessarily integers. The function returns the fare in dollars. For example, a 3.5-km ride with 2.25 minutes of wait costs $11.75. Note that loops and if-statements are neither necessary nor allowed.Yaser Akhrashttps://ww2.mathworks.cn/matlabcentral/profile/authors/14047840tag:ww2.mathworks.cn,2005:Question/6613832020-11-25T05:10:22Z2020-11-30T02:41:29ZConditionally select rows and add to new tableFor example, I have a 2000 x 3 table: Column_1: Datetime Column_2: Rain Column_3: Soil Moisture
The actual table has more variables but I plan to get to it once I know how to undergo the coding.
The idea is to append the rows to a new table if they meet these conditions:
1) While rain > 3 and ends when rain < 2 for 2 subsequent days
2) The 1st condition cannot be less than 4 days
I've been trying to code this out but have gone nowhere:
for i = 1:height(ddtable)
ii = 0;
finaldd(:,:) = [];
while ddtable.RAIN > 3
ii = ii + 1;
if ii < 4
break
elseif ii > 4
finaldd(ddtable);
end
end
endJonathan Cheonghttps://ww2.mathworks.cn/matlabcentral/profile/authors/15392330tag:ww2.mathworks.cn,2005:Question/352582012-04-12T10:28:07Z2020-11-30T02:36:29Zrandomly select elements of an arrayHi
How i can select randomly elements from a matrix o array
I have the matrix and i want to select "x" numbers of elements
thanksNoe alvaradohttps://ww2.mathworks.cn/matlabcentral/profile/authors/3391723tag:ww2.mathworks.cn,2005:Question/4299812018-11-15T05:50:42Z2020-11-30T02:33:51Zam writing a code to add rings on an image but I keep getting a "matrix dimension must agree" erro message, below is the code:i = load('arti.mat');
baseFileName = 0.15*baseFileName + 0.85*i.Q;
subplot(2, 3, 2);ENOC MOGENhttps://ww2.mathworks.cn/matlabcentral/profile/authors/12943785tag:ww2.mathworks.cn,2005:Question/4794192019-09-08T13:32:34Z2020-11-30T02:18:07ZHow can i get the value of start and end of an integral save it in table simulinkI would like to get the start of curve and end of each curve and save it to matrix not in time series datahere are the points that i would like to get only.
Desired Output
Outputlabel={"Start", "end" }
Output=[0.1 10; 11 15 ; 3 145]
jomshttps://ww2.mathworks.cn/matlabcentral/profile/authors/8535596tag:ww2.mathworks.cn,2005:Question/6684332020-11-30T02:16:32Z2020-11-30T02:16:32ZHow to solve gradient based optimizationLhemanhttps://ww2.mathworks.cn/matlabcentral/profile/authors/18476654tag:ww2.mathworks.cn,2005:Question/6683432020-11-29T23:24:25Z2020-11-30T02:14:58ZNot enough input argumentsHi i have a problem with my code and i do not know how to solve it it says that there is not enough input arguments.
Its say the problem is on line 2
function [x,y,z]=Fun_RungK4(f,g,j,x0,y0,z0,a,b,h)
t = a:h:b;
n = length(t);
x = [x0];
y = [y0];
z = [z0];
for i=1:n-1
k1 = h * f(x(i), y(i), z(i), t(i));
l1 = h * g(x(i), y(i), z(i), t(i));
m1 = h * j(x(i), y(i), z(i), t(i));
k2 = h * f(x(i) + (k1/2), y(i) + (l1/2), z(i) + (m1/2), t(i) + (h/2));
l2 = h * g(x(i) + (k1/2), y(i) + (l1/2), z(i) + (m1/2), t(i) + (h/2));
m2 = h * j(x(i) + (k1/2), y(i) + (l1/2), z(i) + (m1/2), t(i) + (h/2));
k3 = h * f(x(i) + (k2/2), y(i) + (l2/2), z(i) + (m2/2), t(i) + (h/2));
l3 = h * g(x(i) + (k2/2), y(i) + (l2/2), z(i) + (m2/2), t(i) + (h/2));
m3 = h * j(x(i) + (k2/2), y(i) + (l2/2), z(i) + (m2/2), t(i) + (h/2));
k4 = h * f(x(i) + k3, y(i) + l3, z(i) + m3, t(i) + h);
l4 = h * g(x(i) + k3, y(i) + l3, z(i) + m3, t(i) + h);
m4 = h * j(x(i) + k3, y(i) + l3, z(i) + m3, t(i) + h);
x(i + 1) = x(i) + ((h/6) * (k1 + (2*k2) + (2*k3) + k4));
y(i + 1) = y(i) + ((h/6) * (l1 + (2*l2) + (2*l3) + l4));
z(i + 1) = z(i) + ((h/6) * (m1 + (2*m2) + (2*m3) + m4));
end
plot3(t,x,t,y,t,z,'-g')
comet3(x,y,x)
endRicardo Gasque Ruizhttps://ww2.mathworks.cn/matlabcentral/profile/authors/16390025