Category: Matlab
Category Archives: Matlab
How can I copy a resource file in a packaged / compiled app?
I have written an app using AppDesigner and I can’t seem to figure out how to save my file using a template I created and placed in the resource folder in my packaged app.
The Error I continue to get is ‘No Matching files were found.’
filename_template = ‘DesignData_template.xlsx’;
[file,path] = uiputfile(sprintf(‘DesignData, Panel %.0f.xlsx’,i));
filename = fullfile(path,file);
copyfile(filename_template, filename, ‘f’);I have written an app using AppDesigner and I can’t seem to figure out how to save my file using a template I created and placed in the resource folder in my packaged app.
The Error I continue to get is ‘No Matching files were found.’
filename_template = ‘DesignData_template.xlsx’;
[file,path] = uiputfile(sprintf(‘DesignData, Panel %.0f.xlsx’,i));
filename = fullfile(path,file);
copyfile(filename_template, filename, ‘f’); I have written an app using AppDesigner and I can’t seem to figure out how to save my file using a template I created and placed in the resource folder in my packaged app.
The Error I continue to get is ‘No Matching files were found.’
filename_template = ‘DesignData_template.xlsx’;
[file,path] = uiputfile(sprintf(‘DesignData, Panel %.0f.xlsx’,i));
filename = fullfile(path,file);
copyfile(filename_template, filename, ‘f’); appdesigner, app designer, save, copyfile, app MATLAB Answers — New Questions
how to let a “plot” immune on any later ” hold off” once this “plot” is created.
I am a Matlab fan.
pls review my Matlab script file below:
clear;clc;
r=10;
plot([-35,35], [0,0], ‘r-.’ )
axis equal
hold on
for h=linspace(0,10,10)
theta=linspace(0,2*pi);
x=r*cos(theta);
y=30+h+r*sin(theta);
plot(x,y);
xlim([-50,50]);
ylim([-50,50]);
pause(0.1)
end
if I don’t add " hold off" in the " for-end" statement, then the circle creates many ones when it is moving.
if I do add " hold off" in the " for-end" statement, then the horizontal red line is disappeared.
I expect :
1) the horizontal red line is kept once it is ploted before the the " for-end" statement.
2) only one circle is occuring when it is moving.
may you give me a guide?
Thanks in advance!I am a Matlab fan.
pls review my Matlab script file below:
clear;clc;
r=10;
plot([-35,35], [0,0], ‘r-.’ )
axis equal
hold on
for h=linspace(0,10,10)
theta=linspace(0,2*pi);
x=r*cos(theta);
y=30+h+r*sin(theta);
plot(x,y);
xlim([-50,50]);
ylim([-50,50]);
pause(0.1)
end
if I don’t add " hold off" in the " for-end" statement, then the circle creates many ones when it is moving.
if I do add " hold off" in the " for-end" statement, then the horizontal red line is disappeared.
I expect :
1) the horizontal red line is kept once it is ploted before the the " for-end" statement.
2) only one circle is occuring when it is moving.
may you give me a guide?
Thanks in advance! I am a Matlab fan.
pls review my Matlab script file below:
clear;clc;
r=10;
plot([-35,35], [0,0], ‘r-.’ )
axis equal
hold on
for h=linspace(0,10,10)
theta=linspace(0,2*pi);
x=r*cos(theta);
y=30+h+r*sin(theta);
plot(x,y);
xlim([-50,50]);
ylim([-50,50]);
pause(0.1)
end
if I don’t add " hold off" in the " for-end" statement, then the circle creates many ones when it is moving.
if I do add " hold off" in the " for-end" statement, then the horizontal red line is disappeared.
I expect :
1) the horizontal red line is kept once it is ploted before the the " for-end" statement.
2) only one circle is occuring when it is moving.
may you give me a guide?
Thanks in advance! plot, hold off, hold on, figure MATLAB Answers — New Questions
Using fmincon to optimize Simulink model for optimal trajectory
Hello, so i want to search for optimal trajectory (by defining spline) position input to the Simulink Simscape Multibody model to minimize the total force input to the model. However, I encountered the following error in constraint function.
Error using chckxy
The first and second inputs must be of type double or single.
Error in spline (line 72)
[x,y,sizey,endslopes] = chckxy(x,y);
Error in GetStartedWithProblemBasedOptimizeLiveEditorTaskExample>constraintFcn (line 43)
dataStructure.signals(1).values=spline(nTime,locX,dataStructure.time);
Besides form that, when I try to exclude the constraint, the solution of the optimal trajectory is always the same with the initial points. Can anyone help me with the situation? Hereby I attach the folder.Hello, so i want to search for optimal trajectory (by defining spline) position input to the Simulink Simscape Multibody model to minimize the total force input to the model. However, I encountered the following error in constraint function.
Error using chckxy
The first and second inputs must be of type double or single.
Error in spline (line 72)
[x,y,sizey,endslopes] = chckxy(x,y);
Error in GetStartedWithProblemBasedOptimizeLiveEditorTaskExample>constraintFcn (line 43)
dataStructure.signals(1).values=spline(nTime,locX,dataStructure.time);
Besides form that, when I try to exclude the constraint, the solution of the optimal trajectory is always the same with the initial points. Can anyone help me with the situation? Hereby I attach the folder. Hello, so i want to search for optimal trajectory (by defining spline) position input to the Simulink Simscape Multibody model to minimize the total force input to the model. However, I encountered the following error in constraint function.
Error using chckxy
The first and second inputs must be of type double or single.
Error in spline (line 72)
[x,y,sizey,endslopes] = chckxy(x,y);
Error in GetStartedWithProblemBasedOptimizeLiveEditorTaskExample>constraintFcn (line 43)
dataStructure.signals(1).values=spline(nTime,locX,dataStructure.time);
Besides form that, when I try to exclude the constraint, the solution of the optimal trajectory is always the same with the initial points. Can anyone help me with the situation? Hereby I attach the folder. optimization, simulink, simscape, trajectory MATLAB Answers — New Questions
matlab code for entropy based local binary pattern
can anyone send me the link for entropy based local binary pattern(ELBP) .. thanks in advancecan anyone send me the link for entropy based local binary pattern(ELBP) .. thanks in advance can anyone send me the link for entropy based local binary pattern(ELBP) .. thanks in advance local binary pattern MATLAB Answers — New Questions
Error while generation detector results
I am using Yolov4 with darknet-53-coco. I have trained the detector but unable to generate detector results using
detectionResults = detect(detector,testData,Threshold=0.01);
After running the code I am getting the following error
Error using dlnetwork/predict
Execution failed during layer(s) ‘conv_2’.
Error in yolov4ObjectDetector>iPredictActivations (line 1223)
[features{:}] = predict(network, dlX, ‘Acceleration’,acceleration);
Error in yolov4ObjectDetector/predict (line 555)
features = iPredictActivations(network, imgBatch, anchorBoxes, predictParams.Acceleration, isRotatedBox);
Error in vision.internal.detector.ObjectDetector/performDetect (line 72)
features = this.predict(Ipreprocessed, params);
Error in yolov4ObjectDetector/detect (line 441)
[varargout{1:nargout}] = performDetect(detector, I, params);
Caused by:
Error using builtin
Out of memory.I am using Yolov4 with darknet-53-coco. I have trained the detector but unable to generate detector results using
detectionResults = detect(detector,testData,Threshold=0.01);
After running the code I am getting the following error
Error using dlnetwork/predict
Execution failed during layer(s) ‘conv_2’.
Error in yolov4ObjectDetector>iPredictActivations (line 1223)
[features{:}] = predict(network, dlX, ‘Acceleration’,acceleration);
Error in yolov4ObjectDetector/predict (line 555)
features = iPredictActivations(network, imgBatch, anchorBoxes, predictParams.Acceleration, isRotatedBox);
Error in vision.internal.detector.ObjectDetector/performDetect (line 72)
features = this.predict(Ipreprocessed, params);
Error in yolov4ObjectDetector/detect (line 441)
[varargout{1:nargout}] = performDetect(detector, I, params);
Caused by:
Error using builtin
Out of memory. I am using Yolov4 with darknet-53-coco. I have trained the detector but unable to generate detector results using
detectionResults = detect(detector,testData,Threshold=0.01);
After running the code I am getting the following error
Error using dlnetwork/predict
Execution failed during layer(s) ‘conv_2’.
Error in yolov4ObjectDetector>iPredictActivations (line 1223)
[features{:}] = predict(network, dlX, ‘Acceleration’,acceleration);
Error in yolov4ObjectDetector/predict (line 555)
features = iPredictActivations(network, imgBatch, anchorBoxes, predictParams.Acceleration, isRotatedBox);
Error in vision.internal.detector.ObjectDetector/performDetect (line 72)
features = this.predict(Ipreprocessed, params);
Error in yolov4ObjectDetector/detect (line 441)
[varargout{1:nargout}] = performDetect(detector, I, params);
Caused by:
Error using builtin
Out of memory. yolov4, object detection MATLAB Answers — New Questions
How to exclude Simulink blocks from code generation?
Basically, my project is: to acquire data from a USB webcam and perform some color thresholding and object tracking.
The output obtained from these blocks is then given to Arduino for hardware implementation. Now if I directly build the model, it generates code for the whole model and then deploys to Arduino board which is basically consuming more memory and making my model to run at a slower speed.
How can exclude these blocks(computer vision and image processing toolbox) from code generation?Basically, my project is: to acquire data from a USB webcam and perform some color thresholding and object tracking.
The output obtained from these blocks is then given to Arduino for hardware implementation. Now if I directly build the model, it generates code for the whole model and then deploys to Arduino board which is basically consuming more memory and making my model to run at a slower speed.
How can exclude these blocks(computer vision and image processing toolbox) from code generation? Basically, my project is: to acquire data from a USB webcam and perform some color thresholding and object tracking.
The output obtained from these blocks is then given to Arduino for hardware implementation. Now if I directly build the model, it generates code for the whole model and then deploys to Arduino board which is basically consuming more memory and making my model to run at a slower speed.
How can exclude these blocks(computer vision and image processing toolbox) from code generation? simulink, arduino, maker MATLAB Answers — New Questions
How can I load GDS II into matlab?
I want to load GDS II layout format into matlab in the form of a matrix, how can I do that?I want to load GDS II layout format into matlab in the form of a matrix, how can I do that? I want to load GDS II layout format into matlab in the form of a matrix, how can I do that? gds ii MATLAB Answers — New Questions
how to crop image automatically to 512x512px?
Hello everyone. I want to crop with the size of 512x512px. But matlab only save the image as 10×9 uint8. and also, I want it to crop at the center of the lesion without any specific area. can the matlab do such that task? here’s my code given below and result of the image that not at the center of the lesion.
close all;
I=imread(‘1_245.jpg’);
figure, imshow(I);
I=rgb2gray(I);
BW=I>100;
figure,imshow(BW);
labeledImage = bwlabel(BW);
measurements = regionprops(labeledImage, ‘BoundingBox’, ‘Area’);
for k = 1 : length(measurements)
thisBB = measurements(k).BoundingBox;
I2=imcrop(I,[thisBB(1),thisBB(2),thisBB(3),thisBB(4)]);
[rows, cols, depth]=size(I2);
if rows*cols>100
I2=imresize(I2,[512 512]);
figure,imshow(I2);
end
endHello everyone. I want to crop with the size of 512x512px. But matlab only save the image as 10×9 uint8. and also, I want it to crop at the center of the lesion without any specific area. can the matlab do such that task? here’s my code given below and result of the image that not at the center of the lesion.
close all;
I=imread(‘1_245.jpg’);
figure, imshow(I);
I=rgb2gray(I);
BW=I>100;
figure,imshow(BW);
labeledImage = bwlabel(BW);
measurements = regionprops(labeledImage, ‘BoundingBox’, ‘Area’);
for k = 1 : length(measurements)
thisBB = measurements(k).BoundingBox;
I2=imcrop(I,[thisBB(1),thisBB(2),thisBB(3),thisBB(4)]);
[rows, cols, depth]=size(I2);
if rows*cols>100
I2=imresize(I2,[512 512]);
figure,imshow(I2);
end
end Hello everyone. I want to crop with the size of 512x512px. But matlab only save the image as 10×9 uint8. and also, I want it to crop at the center of the lesion without any specific area. can the matlab do such that task? here’s my code given below and result of the image that not at the center of the lesion.
close all;
I=imread(‘1_245.jpg’);
figure, imshow(I);
I=rgb2gray(I);
BW=I>100;
figure,imshow(BW);
labeledImage = bwlabel(BW);
measurements = regionprops(labeledImage, ‘BoundingBox’, ‘Area’);
for k = 1 : length(measurements)
thisBB = measurements(k).BoundingBox;
I2=imcrop(I,[thisBB(1),thisBB(2),thisBB(3),thisBB(4)]);
[rows, cols, depth]=size(I2);
if rows*cols>100
I2=imresize(I2,[512 512]);
figure,imshow(I2);
end
end auto crop MATLAB Answers — New Questions
Error keeps appearing with h2e function used to obtain XYZ positions
Estaba diseñando un brazo robotico de 6 gdl (tomando de referencia un ABB IRB 1200) utilzando la libreria de Peter Corke, pero cuando intento utilizar la funcion h2e para obtener la posicion final del ultimo eslabon, esta me lanza el siguiente error.
I was designing a 6 DOF robotic arm (using an ABB IRB 1200 as reference) using Peter Corke’s library, but when I try to use the h2e function to obtain the final position of the last link, it throws the following error.
Error using assert
LHS should be matrix with 3 rows
Error in * (line 357)
assert(numrows(a) == n-1, ‘SMTB:RTBPose:badops’, ‘LHS should be matrix with %d rows’, n-1);
Error in Cinematica_Robot_Manipulador_IRB1200 (line 52)
h2e(dh*[0 0 0 1]’)’*100 % Posicion en X Y Z
El codigo que utilice fue uno que nos presento nuestro profesor, que es el siguiente:
The code I used was one that our teacher presented to us, which is the following:
close all
clc
%% Esta parte resuelve la cinematica directa del robot IRB 1200
syms q1 q2 q3 q4 q5 q6 % variables para los angulos de rotacion de las articulaciones
% Se declaran las logitudes de los eslabones
L1 = 399.1*1e-2;
L2 = 350*1e-2;
L3 = 175.5*1e-2;
L4 = 175.5*1e-2;
L5 = 82*1e-2;
% Se anota la cinematica directa segun D-H
A1 = trotz(q1)*transl(0,0,L1)*transl(0,0,0)*trotx(-pi/2);
A2 = trotz(q2-pi/2)*transl(0,0,0)*transl(L2,0,0)*trotx(0);
A3 = trotz(q3)*transl(0,0,0)*transl(L3,0,0)*trotx(-pi/2);
A4 = trotz(q4)*transl(0,0,L4)*transl(0,0,0)*trotx(pi/2);
A5 = trotz(q5)*transl(0,0,0)*transl(0,0,0)*trotx(-pi/2);
A6 = trotz(q6)*transl(0,0,L5)*transl(0,0,0)*trotx(0);
%% Se evalua la matriz de transmormacion total
T = A1*A2*A3*A4*A5*A6;
% Se le asignan valores a la articulaciones
q1 = 91.34 *pi/180;
q2 = 31.02 *pi/180;
q3 = -38.58 *pi/180;
q4 = -21.94 *pi/180;
q5 = 52.78 *pi/180;
q6 = -23.73 *pi/180;
%% Se declaran los eslabones y rotaciones conrtantes
dh1 = Link("d",L1,’a’,0,’alpha’,-pi/2);
dh2 = Link("d",0,’a’,L2,’alpha’,0);
dh3 = Link("d",0,’a’,L3,’alpha’,-pi/2);
dh4 = Link("d",L4,’a’,0,’alpha’,pi/2);
dh5 = Link("d",0,’a’,0,’alpha’,-pi/2);
dh6 = Link("d",L5,’a’,0,’alpha’,0);
%% Se ensamblan los eslabones.
rob = SerialLink ([dh1 dh2 dh3 dh4 dh5 dh6],’name’,’IRB 1200′);
q = [q1 q2-pi/2 q3 q4 q5 q6];
% Se dibuja el robot en el espacio 3D
figure(1)
rob.plot(q,’workspace’,[-15 15 -15 15 0 15],’view’,[45 30]);
hold on
% Se obtiene la matriz de transformacion del modelo
dh = fkine(rob,q);
h2e(dh*[0 0 0 1]’)’*100 % Posicion en X Y ZEstaba diseñando un brazo robotico de 6 gdl (tomando de referencia un ABB IRB 1200) utilzando la libreria de Peter Corke, pero cuando intento utilizar la funcion h2e para obtener la posicion final del ultimo eslabon, esta me lanza el siguiente error.
I was designing a 6 DOF robotic arm (using an ABB IRB 1200 as reference) using Peter Corke’s library, but when I try to use the h2e function to obtain the final position of the last link, it throws the following error.
Error using assert
LHS should be matrix with 3 rows
Error in * (line 357)
assert(numrows(a) == n-1, ‘SMTB:RTBPose:badops’, ‘LHS should be matrix with %d rows’, n-1);
Error in Cinematica_Robot_Manipulador_IRB1200 (line 52)
h2e(dh*[0 0 0 1]’)’*100 % Posicion en X Y Z
El codigo que utilice fue uno que nos presento nuestro profesor, que es el siguiente:
The code I used was one that our teacher presented to us, which is the following:
close all
clc
%% Esta parte resuelve la cinematica directa del robot IRB 1200
syms q1 q2 q3 q4 q5 q6 % variables para los angulos de rotacion de las articulaciones
% Se declaran las logitudes de los eslabones
L1 = 399.1*1e-2;
L2 = 350*1e-2;
L3 = 175.5*1e-2;
L4 = 175.5*1e-2;
L5 = 82*1e-2;
% Se anota la cinematica directa segun D-H
A1 = trotz(q1)*transl(0,0,L1)*transl(0,0,0)*trotx(-pi/2);
A2 = trotz(q2-pi/2)*transl(0,0,0)*transl(L2,0,0)*trotx(0);
A3 = trotz(q3)*transl(0,0,0)*transl(L3,0,0)*trotx(-pi/2);
A4 = trotz(q4)*transl(0,0,L4)*transl(0,0,0)*trotx(pi/2);
A5 = trotz(q5)*transl(0,0,0)*transl(0,0,0)*trotx(-pi/2);
A6 = trotz(q6)*transl(0,0,L5)*transl(0,0,0)*trotx(0);
%% Se evalua la matriz de transmormacion total
T = A1*A2*A3*A4*A5*A6;
% Se le asignan valores a la articulaciones
q1 = 91.34 *pi/180;
q2 = 31.02 *pi/180;
q3 = -38.58 *pi/180;
q4 = -21.94 *pi/180;
q5 = 52.78 *pi/180;
q6 = -23.73 *pi/180;
%% Se declaran los eslabones y rotaciones conrtantes
dh1 = Link("d",L1,’a’,0,’alpha’,-pi/2);
dh2 = Link("d",0,’a’,L2,’alpha’,0);
dh3 = Link("d",0,’a’,L3,’alpha’,-pi/2);
dh4 = Link("d",L4,’a’,0,’alpha’,pi/2);
dh5 = Link("d",0,’a’,0,’alpha’,-pi/2);
dh6 = Link("d",L5,’a’,0,’alpha’,0);
%% Se ensamblan los eslabones.
rob = SerialLink ([dh1 dh2 dh3 dh4 dh5 dh6],’name’,’IRB 1200′);
q = [q1 q2-pi/2 q3 q4 q5 q6];
% Se dibuja el robot en el espacio 3D
figure(1)
rob.plot(q,’workspace’,[-15 15 -15 15 0 15],’view’,[45 30]);
hold on
% Se obtiene la matriz de transformacion del modelo
dh = fkine(rob,q);
h2e(dh*[0 0 0 1]’)’*100 % Posicion en X Y Z Estaba diseñando un brazo robotico de 6 gdl (tomando de referencia un ABB IRB 1200) utilzando la libreria de Peter Corke, pero cuando intento utilizar la funcion h2e para obtener la posicion final del ultimo eslabon, esta me lanza el siguiente error.
I was designing a 6 DOF robotic arm (using an ABB IRB 1200 as reference) using Peter Corke’s library, but when I try to use the h2e function to obtain the final position of the last link, it throws the following error.
Error using assert
LHS should be matrix with 3 rows
Error in * (line 357)
assert(numrows(a) == n-1, ‘SMTB:RTBPose:badops’, ‘LHS should be matrix with %d rows’, n-1);
Error in Cinematica_Robot_Manipulador_IRB1200 (line 52)
h2e(dh*[0 0 0 1]’)’*100 % Posicion en X Y Z
El codigo que utilice fue uno que nos presento nuestro profesor, que es el siguiente:
The code I used was one that our teacher presented to us, which is the following:
close all
clc
%% Esta parte resuelve la cinematica directa del robot IRB 1200
syms q1 q2 q3 q4 q5 q6 % variables para los angulos de rotacion de las articulaciones
% Se declaran las logitudes de los eslabones
L1 = 399.1*1e-2;
L2 = 350*1e-2;
L3 = 175.5*1e-2;
L4 = 175.5*1e-2;
L5 = 82*1e-2;
% Se anota la cinematica directa segun D-H
A1 = trotz(q1)*transl(0,0,L1)*transl(0,0,0)*trotx(-pi/2);
A2 = trotz(q2-pi/2)*transl(0,0,0)*transl(L2,0,0)*trotx(0);
A3 = trotz(q3)*transl(0,0,0)*transl(L3,0,0)*trotx(-pi/2);
A4 = trotz(q4)*transl(0,0,L4)*transl(0,0,0)*trotx(pi/2);
A5 = trotz(q5)*transl(0,0,0)*transl(0,0,0)*trotx(-pi/2);
A6 = trotz(q6)*transl(0,0,L5)*transl(0,0,0)*trotx(0);
%% Se evalua la matriz de transmormacion total
T = A1*A2*A3*A4*A5*A6;
% Se le asignan valores a la articulaciones
q1 = 91.34 *pi/180;
q2 = 31.02 *pi/180;
q3 = -38.58 *pi/180;
q4 = -21.94 *pi/180;
q5 = 52.78 *pi/180;
q6 = -23.73 *pi/180;
%% Se declaran los eslabones y rotaciones conrtantes
dh1 = Link("d",L1,’a’,0,’alpha’,-pi/2);
dh2 = Link("d",0,’a’,L2,’alpha’,0);
dh3 = Link("d",0,’a’,L3,’alpha’,-pi/2);
dh4 = Link("d",L4,’a’,0,’alpha’,pi/2);
dh5 = Link("d",0,’a’,0,’alpha’,-pi/2);
dh6 = Link("d",L5,’a’,0,’alpha’,0);
%% Se ensamblan los eslabones.
rob = SerialLink ([dh1 dh2 dh3 dh4 dh5 dh6],’name’,’IRB 1200′);
q = [q1 q2-pi/2 q3 q4 q5 q6];
% Se dibuja el robot en el espacio 3D
figure(1)
rob.plot(q,’workspace’,[-15 15 -15 15 0 15],’view’,[45 30]);
hold on
% Se obtiene la matriz de transformacion del modelo
dh = fkine(rob,q);
h2e(dh*[0 0 0 1]’)’*100 % Posicion en X Y Z robotics, error, matrix, peter corke MATLAB Answers — New Questions
When using ‘quadprog’ how do I limit certain solutions so that they can only become whole numbers?
As stated above, I am trying to minimize a quadratic function where some of the solutions have to be whole numbers for the function to work.
I have done a similar problem to this one but with a linear function, however in that case I only had to set the desired solutions as integers and then use ‘intlinprog’. Unfortunately there is no such option (to my knowledge) for ‘quadprog’ so I’m interested to know if someone has a possible workaround.
Thank You!As stated above, I am trying to minimize a quadratic function where some of the solutions have to be whole numbers for the function to work.
I have done a similar problem to this one but with a linear function, however in that case I only had to set the desired solutions as integers and then use ‘intlinprog’. Unfortunately there is no such option (to my knowledge) for ‘quadprog’ so I’m interested to know if someone has a possible workaround.
Thank You! As stated above, I am trying to minimize a quadratic function where some of the solutions have to be whole numbers for the function to work.
I have done a similar problem to this one but with a linear function, however in that case I only had to set the desired solutions as integers and then use ‘intlinprog’. Unfortunately there is no such option (to my knowledge) for ‘quadprog’ so I’m interested to know if someone has a possible workaround.
Thank You! optimization, nonlinear MATLAB Answers — New Questions
I need a big project containing smart grid with self healing methods
Iam a 5th year master student with a thesis about self healing in smart grids, i need a big simulation with results if available, thank you very much.Iam a 5th year master student with a thesis about self healing in smart grids, i need a big simulation with results if available, thank you very much. Iam a 5th year master student with a thesis about self healing in smart grids, i need a big simulation with results if available, thank you very much. self healing in smart grids MATLAB Answers — New Questions
Need help to correct and modify MATLAB code
I have the following code :
%===============================%
clc
close all;
clear;
% Define the given arrays
x = [0.02 0.55 1.00 1.4 1.4 2.32 2.62 …
3.77 4.81 5.61 6.29 6.29 6.00 …
6.00 7.00 7.00 7.00];
z = [5 5 5 5 5 4 4 4 4 4 4 4 2 2 2 2 2];
% Find sudden changes in depth
sudden_changes = diff(z);
% Find indices where sudden changes occur
fault_indices = find(sudden_changes ~= 0) + 1;
% Plot the top of the rock formation
plot(x, z, ‘-o’);
hold on;
% Plot fault lines
for i = 1:length(fault_indices)
idx = fault_indices(i);
plot([x(idx-1), x(idx)], [z(idx-1), z(idx)], ‘r–‘);
end
% Calculate dip angle using the tan-rule
dip_angles = atand(diff(z) ./ diff(x));
% Identify normal and reverse faults
normal_faults = dip_angles <= 90;
reverse_faults = dip_angles > 90;
% Plot normal faults
scatter(x(fault_indices(normal_faults)), z(fault_indices(normal_faults)), ‘g’, ‘filled’);
% Plot reverse faults
scatter(x(fault_indices(reverse_faults)), z(fault_indices(reverse_faults)), ‘m’, ‘filled’);
% Add labels and legend
xlabel(‘X-axis’);
ylabel(‘Depth’);
title(‘Top of the rock formation with fault lines’);
legend(‘Top of the rock formation’, ‘Fault lines’, ‘Normal faults’, ‘Reverse faults’);
set(gca, ‘YDir’, ‘reverse’);
grid on;
%===============================%
I need to draw the Earth’s surface where the depth is constan surface and equal to zero
and need th extend the the fault lines to the Earths surface as shown in attached figure
and need to detect the type of fault from intersected fault line with Earth’s surfaceI have the following code :
%===============================%
clc
close all;
clear;
% Define the given arrays
x = [0.02 0.55 1.00 1.4 1.4 2.32 2.62 …
3.77 4.81 5.61 6.29 6.29 6.00 …
6.00 7.00 7.00 7.00];
z = [5 5 5 5 5 4 4 4 4 4 4 4 2 2 2 2 2];
% Find sudden changes in depth
sudden_changes = diff(z);
% Find indices where sudden changes occur
fault_indices = find(sudden_changes ~= 0) + 1;
% Plot the top of the rock formation
plot(x, z, ‘-o’);
hold on;
% Plot fault lines
for i = 1:length(fault_indices)
idx = fault_indices(i);
plot([x(idx-1), x(idx)], [z(idx-1), z(idx)], ‘r–‘);
end
% Calculate dip angle using the tan-rule
dip_angles = atand(diff(z) ./ diff(x));
% Identify normal and reverse faults
normal_faults = dip_angles <= 90;
reverse_faults = dip_angles > 90;
% Plot normal faults
scatter(x(fault_indices(normal_faults)), z(fault_indices(normal_faults)), ‘g’, ‘filled’);
% Plot reverse faults
scatter(x(fault_indices(reverse_faults)), z(fault_indices(reverse_faults)), ‘m’, ‘filled’);
% Add labels and legend
xlabel(‘X-axis’);
ylabel(‘Depth’);
title(‘Top of the rock formation with fault lines’);
legend(‘Top of the rock formation’, ‘Fault lines’, ‘Normal faults’, ‘Reverse faults’);
set(gca, ‘YDir’, ‘reverse’);
grid on;
%===============================%
I need to draw the Earth’s surface where the depth is constan surface and equal to zero
and need th extend the the fault lines to the Earths surface as shown in attached figure
and need to detect the type of fault from intersected fault line with Earth’s surface I have the following code :
%===============================%
clc
close all;
clear;
% Define the given arrays
x = [0.02 0.55 1.00 1.4 1.4 2.32 2.62 …
3.77 4.81 5.61 6.29 6.29 6.00 …
6.00 7.00 7.00 7.00];
z = [5 5 5 5 5 4 4 4 4 4 4 4 2 2 2 2 2];
% Find sudden changes in depth
sudden_changes = diff(z);
% Find indices where sudden changes occur
fault_indices = find(sudden_changes ~= 0) + 1;
% Plot the top of the rock formation
plot(x, z, ‘-o’);
hold on;
% Plot fault lines
for i = 1:length(fault_indices)
idx = fault_indices(i);
plot([x(idx-1), x(idx)], [z(idx-1), z(idx)], ‘r–‘);
end
% Calculate dip angle using the tan-rule
dip_angles = atand(diff(z) ./ diff(x));
% Identify normal and reverse faults
normal_faults = dip_angles <= 90;
reverse_faults = dip_angles > 90;
% Plot normal faults
scatter(x(fault_indices(normal_faults)), z(fault_indices(normal_faults)), ‘g’, ‘filled’);
% Plot reverse faults
scatter(x(fault_indices(reverse_faults)), z(fault_indices(reverse_faults)), ‘m’, ‘filled’);
% Add labels and legend
xlabel(‘X-axis’);
ylabel(‘Depth’);
title(‘Top of the rock formation with fault lines’);
legend(‘Top of the rock formation’, ‘Fault lines’, ‘Normal faults’, ‘Reverse faults’);
set(gca, ‘YDir’, ‘reverse’);
grid on;
%===============================%
I need to draw the Earth’s surface where the depth is constan surface and equal to zero
and need th extend the the fault lines to the Earths surface as shown in attached figure
and need to detect the type of fault from intersected fault line with Earth’s surface line, line break MATLAB Answers — New Questions
Removing empty cells from cell array with multiple rows while preserving the rows
I have cell array of string values with empty cells in some of in the middle of some of the rows. I would like to delete the empty cells and shift the cells to the left but I don’t want any shifting to happen in between rows. I tried the code below but it returns cell array of cell arrays. How can I modified the code so it returns a cell array of string values like the orginal array but only the empty cells removed?
compacted_instances = {};
for i = 1:size(instance_array_nolateral, 1)
% Get the current row
current_row = instance_array_nolateral(i,:);
current_row = {current_row};
% Remove empty cells from the current row
compacted_row = current_row(~cellfun(‘isempty’, current_row));
% Store the compacted row in the new cell array
compacted_instances{i} = compacted_row;
endI have cell array of string values with empty cells in some of in the middle of some of the rows. I would like to delete the empty cells and shift the cells to the left but I don’t want any shifting to happen in between rows. I tried the code below but it returns cell array of cell arrays. How can I modified the code so it returns a cell array of string values like the orginal array but only the empty cells removed?
compacted_instances = {};
for i = 1:size(instance_array_nolateral, 1)
% Get the current row
current_row = instance_array_nolateral(i,:);
current_row = {current_row};
% Remove empty cells from the current row
compacted_row = current_row(~cellfun(‘isempty’, current_row));
% Store the compacted row in the new cell array
compacted_instances{i} = compacted_row;
end I have cell array of string values with empty cells in some of in the middle of some of the rows. I would like to delete the empty cells and shift the cells to the left but I don’t want any shifting to happen in between rows. I tried the code below but it returns cell array of cell arrays. How can I modified the code so it returns a cell array of string values like the orginal array but only the empty cells removed?
compacted_instances = {};
for i = 1:size(instance_array_nolateral, 1)
% Get the current row
current_row = instance_array_nolateral(i,:);
current_row = {current_row};
% Remove empty cells from the current row
compacted_row = current_row(~cellfun(‘isempty’, current_row));
% Store the compacted row in the new cell array
compacted_instances{i} = compacted_row;
end cell arrays MATLAB Answers — New Questions
Selecting appropriate values for the parameters in the Gierer-Meinhardt activator-inhibitor model
For the following activator-inhibitor system (Alfred Gierer-Hans Meinhardt model),
with all constants positive and initial conditions , examine the effect of the parameters () on the behavior of concentrations . Initially, we have to consider .
My problem is that I don’t undestand how to choose the right parameters every time. For example but the code works and for or but when I chose you can see below, the results are not correct.
Could anyone explain please? Thanks in advance
Parameter k : Range: 0.01 to 1
% Define common parameters
P = 0.75; % Production rate of u
a = 1; % rate of u inhibition by v
b = 0.9; % Production rate of v stimulated by u
mu = 0.5; % Decay rate of u
ks = [0.01, 0.1, 1];
T = 10; % Total simulation time
dt = 0.01; % Time step
t = 0:dt:T; % Time vector
% Initial conditions
u0 = 1; % Initial concentration of u
v0 = 0.5; % Initial concentration of v
%% Initialize a figure
figure(1);
hold on
%% Loop through each k value
for k = ks
N = length(t); % Number of time steps
% Initialize arrays for u and v
u = zeros(1, N);
v = zeros(1, N);
% Set initial conditions
u(1) = u0;
v(1) = v0;
% Simulate the system’s response
for i = 2:N
% Calculate the changes in u and v using the system equations
f1 = P – a * (u(i-1)^2 / v(i-1)) – mu * u(i-1); % Change in activator
f2 = b * u(i-1)^2 – k * v(i-1); % Change in inhibitor
% Update u and v using Euler’s method
u(i) = u(i-1) + dt * f1;
v(i) = v(i-1) + dt * f2;
end
% Plot the concentration of u and v for the current k value
plot(t, u, ‘DisplayName’, [‘u(t), k = ‘, num2str(k)]);
plot(t, v, ‘–‘, ‘DisplayName’, [‘v(t), k = ‘, num2str(k)]);
end
%% Add labels, legend, and grid to the plot
xlabel(‘Time (s)’);
ylabel(‘Concentration’);
title(‘Dynamics of u and v over Time for Different k Values’);
legend(‘show’);
grid on;
hold off;
Parameter : Range: 0.01 to 1
% Define common parameters
P = 0.75; % Production rate of u
a = 1; % Rate of u inhibition by v
b = 0.9; % Production rate of v stimulated by u
k = 1; % Decay rate of v (fixed in this scenario)
mus = [0.01, 0.1, 9]; % Different decay rates of u to test
T = 10; % Total simulation time
dt = 0.01; % Time step
t = 0:dt:T; % Time vector
% Initial conditions
u0 = 1; % Initial concentration of u
v0 = 0.5; % Initial concentration of v
%% Initialize a figure
figure(2);
hold on
%% Loop through each mu value
for mu = mus
N = length(t); % Number of time steps
% Initialize arrays for u and v
u = zeros(1, N);
v = zeros(1, N);
% Set initial conditions
u(1) = u0;
v(1) = v0;
% Simulate the system’s response
for i = 2:N
% Calculate the changes in u and v using the system equations
f1 = P – a * (u(i-1)^2 / v(i-1)) – mu * u(i-1); % Change in activator
f2 = b * u(i-1)^2 – k * v(i-1); % Change in inhibitor
% Update u and v using Euler’s method
u(i) = u(i-1) + dt * f1;
v(i) = v(i-1) + dt * f2;
end
% Plot the concentration of u and v for the current mu value
plot(t, u, ‘DisplayName’, [‘u(t), mu = ‘, num2str(mu)]);
plot(t, v, ‘–‘, ‘DisplayName’, [‘v(t), mu = ‘, num2str(mu)]);
end
%% Add labels, legend, and grid to the plot
xlabel(‘Time (s)’);
ylabel(‘Concentration’);
title(‘Dynamics of u and v over Time for Different mu Values’);
legend(‘show’);
grid on;
hold off;
Parameter b : Range: 0.01 to 10
% Define common parameters
P = 0.75; % Production rate of u
a = 1; % Rate of u inhibition by v
mu = 0.5; % Decay rate of u
k = 1; % Decay rate of v
bs = [0.1, 1, 9.9]; % Different rates for b to test
T = 10; % Total simulation time
dt = 0.01; % Time step
t = 0:dt:T; % Time vector
% Initial conditions
u0 = 1; % Initial concentration of u
v0 = 0.5; % Initial concentration of v
%% Initialize a figure
figure(3);
hold on
%% Loop through each b value
for b = bs
N = length(t); % Number of time steps
% Initialize arrays for u and v
u = zeros(1, N);
v = zeros(1, N);
% Set initial conditions
u(1) = u0;
v(1) = v0;
% Simulate the system’s response
for i = 2:N
% Calculate the changes in u and v using the system equations
f1 = P – a * (u(i-1)^2 / v(i-1)) – mu * u(i-1); % Change in activator
f2 = b * u(i-1)^2 – k * v(i-1); % Change in inhibitor
% Update u and v using Euler’s method
u(i) = u(i-1) + dt * f1;
v(i) = v(i-1) + dt * f2;
end
% Plot the concentration of u and v for the current b value
plot(t, u, ‘DisplayName’, [‘u(t), b = ‘, num2str(b)]);
plot(t, v, ‘–‘, ‘DisplayName’, [‘v(t), b = ‘, num2str(b)]);
end
%% Add labels, legend, and grid to the plot
xlabel(‘Time (s)’);
ylabel(‘Concentration’);
title(‘Dynamics of u and v over Time for Different b Values’);
legend(‘show’);
grid on;
hold off;
Parameter a : Range: 0.1 to 10
% Define common parameters
P = 0.75; % Production rate of u
b = 0.9; % Production rate of v stimulated by u
mu = 0.5; % Decay rate of u
k = 1; % Decay rate of v (constant in this scenario)
as = [0.1, 1, 9.9]; % Different rates of a to test
T = 10; % Total simulation time
dt = 0.01; % Time step
t = 0:dt:T; % Time vector
% Initial conditions
u0 = 1; % Initial concentration of u
v0 = 0.5; % Initial concentration of v
%% Initialize a figure
figure(4);
hold on
%% Loop through each a value
for a = as
N = length(t); % Number of time steps
% Initialize arrays for u and v
u = zeros(1, N);
v = zeros(1, N);
% Set initial conditions
u(1) = u0;
v(1) = v0;
% Simulate the system’s response
for i = 2:N
% Calculate the changes in u and v using the system equations
f1 = P – a * (u(i-1)^2 / v(i-1)) – mu * u(i-1); % Change in activator
f2 = b * u(i-1)^2 – k * v(i-1); % Change in inhibitor
% Update u and v using Euler’s method
u(i) = u(i-1) + dt * f1;
v(i) = v(i-1) + dt * f2;
end
% Plot the concentration of u and v for the current a value
plot(t, u, ‘DisplayName’, [‘u(t), a = ‘, num2str(a)]);
plot(t, v, ‘–‘, ‘DisplayName’, [‘v(t), a = ‘, num2str(a)]);
end
%% Add labels, legend, and grid to the plot
xlabel(‘Time (s)’);
ylabel(‘Concentration’);
title(‘Dynamics of u and v over Time for Different a Values’);
legend(‘show’);
grid on;
hold off;For the following activator-inhibitor system (Alfred Gierer-Hans Meinhardt model),
with all constants positive and initial conditions , examine the effect of the parameters () on the behavior of concentrations . Initially, we have to consider .
My problem is that I don’t undestand how to choose the right parameters every time. For example but the code works and for or but when I chose you can see below, the results are not correct.
Could anyone explain please? Thanks in advance
Parameter k : Range: 0.01 to 1
% Define common parameters
P = 0.75; % Production rate of u
a = 1; % rate of u inhibition by v
b = 0.9; % Production rate of v stimulated by u
mu = 0.5; % Decay rate of u
ks = [0.01, 0.1, 1];
T = 10; % Total simulation time
dt = 0.01; % Time step
t = 0:dt:T; % Time vector
% Initial conditions
u0 = 1; % Initial concentration of u
v0 = 0.5; % Initial concentration of v
%% Initialize a figure
figure(1);
hold on
%% Loop through each k value
for k = ks
N = length(t); % Number of time steps
% Initialize arrays for u and v
u = zeros(1, N);
v = zeros(1, N);
% Set initial conditions
u(1) = u0;
v(1) = v0;
% Simulate the system’s response
for i = 2:N
% Calculate the changes in u and v using the system equations
f1 = P – a * (u(i-1)^2 / v(i-1)) – mu * u(i-1); % Change in activator
f2 = b * u(i-1)^2 – k * v(i-1); % Change in inhibitor
% Update u and v using Euler’s method
u(i) = u(i-1) + dt * f1;
v(i) = v(i-1) + dt * f2;
end
% Plot the concentration of u and v for the current k value
plot(t, u, ‘DisplayName’, [‘u(t), k = ‘, num2str(k)]);
plot(t, v, ‘–‘, ‘DisplayName’, [‘v(t), k = ‘, num2str(k)]);
end
%% Add labels, legend, and grid to the plot
xlabel(‘Time (s)’);
ylabel(‘Concentration’);
title(‘Dynamics of u and v over Time for Different k Values’);
legend(‘show’);
grid on;
hold off;
Parameter : Range: 0.01 to 1
% Define common parameters
P = 0.75; % Production rate of u
a = 1; % Rate of u inhibition by v
b = 0.9; % Production rate of v stimulated by u
k = 1; % Decay rate of v (fixed in this scenario)
mus = [0.01, 0.1, 9]; % Different decay rates of u to test
T = 10; % Total simulation time
dt = 0.01; % Time step
t = 0:dt:T; % Time vector
% Initial conditions
u0 = 1; % Initial concentration of u
v0 = 0.5; % Initial concentration of v
%% Initialize a figure
figure(2);
hold on
%% Loop through each mu value
for mu = mus
N = length(t); % Number of time steps
% Initialize arrays for u and v
u = zeros(1, N);
v = zeros(1, N);
% Set initial conditions
u(1) = u0;
v(1) = v0;
% Simulate the system’s response
for i = 2:N
% Calculate the changes in u and v using the system equations
f1 = P – a * (u(i-1)^2 / v(i-1)) – mu * u(i-1); % Change in activator
f2 = b * u(i-1)^2 – k * v(i-1); % Change in inhibitor
% Update u and v using Euler’s method
u(i) = u(i-1) + dt * f1;
v(i) = v(i-1) + dt * f2;
end
% Plot the concentration of u and v for the current mu value
plot(t, u, ‘DisplayName’, [‘u(t), mu = ‘, num2str(mu)]);
plot(t, v, ‘–‘, ‘DisplayName’, [‘v(t), mu = ‘, num2str(mu)]);
end
%% Add labels, legend, and grid to the plot
xlabel(‘Time (s)’);
ylabel(‘Concentration’);
title(‘Dynamics of u and v over Time for Different mu Values’);
legend(‘show’);
grid on;
hold off;
Parameter b : Range: 0.01 to 10
% Define common parameters
P = 0.75; % Production rate of u
a = 1; % Rate of u inhibition by v
mu = 0.5; % Decay rate of u
k = 1; % Decay rate of v
bs = [0.1, 1, 9.9]; % Different rates for b to test
T = 10; % Total simulation time
dt = 0.01; % Time step
t = 0:dt:T; % Time vector
% Initial conditions
u0 = 1; % Initial concentration of u
v0 = 0.5; % Initial concentration of v
%% Initialize a figure
figure(3);
hold on
%% Loop through each b value
for b = bs
N = length(t); % Number of time steps
% Initialize arrays for u and v
u = zeros(1, N);
v = zeros(1, N);
% Set initial conditions
u(1) = u0;
v(1) = v0;
% Simulate the system’s response
for i = 2:N
% Calculate the changes in u and v using the system equations
f1 = P – a * (u(i-1)^2 / v(i-1)) – mu * u(i-1); % Change in activator
f2 = b * u(i-1)^2 – k * v(i-1); % Change in inhibitor
% Update u and v using Euler’s method
u(i) = u(i-1) + dt * f1;
v(i) = v(i-1) + dt * f2;
end
% Plot the concentration of u and v for the current b value
plot(t, u, ‘DisplayName’, [‘u(t), b = ‘, num2str(b)]);
plot(t, v, ‘–‘, ‘DisplayName’, [‘v(t), b = ‘, num2str(b)]);
end
%% Add labels, legend, and grid to the plot
xlabel(‘Time (s)’);
ylabel(‘Concentration’);
title(‘Dynamics of u and v over Time for Different b Values’);
legend(‘show’);
grid on;
hold off;
Parameter a : Range: 0.1 to 10
% Define common parameters
P = 0.75; % Production rate of u
b = 0.9; % Production rate of v stimulated by u
mu = 0.5; % Decay rate of u
k = 1; % Decay rate of v (constant in this scenario)
as = [0.1, 1, 9.9]; % Different rates of a to test
T = 10; % Total simulation time
dt = 0.01; % Time step
t = 0:dt:T; % Time vector
% Initial conditions
u0 = 1; % Initial concentration of u
v0 = 0.5; % Initial concentration of v
%% Initialize a figure
figure(4);
hold on
%% Loop through each a value
for a = as
N = length(t); % Number of time steps
% Initialize arrays for u and v
u = zeros(1, N);
v = zeros(1, N);
% Set initial conditions
u(1) = u0;
v(1) = v0;
% Simulate the system’s response
for i = 2:N
% Calculate the changes in u and v using the system equations
f1 = P – a * (u(i-1)^2 / v(i-1)) – mu * u(i-1); % Change in activator
f2 = b * u(i-1)^2 – k * v(i-1); % Change in inhibitor
% Update u and v using Euler’s method
u(i) = u(i-1) + dt * f1;
v(i) = v(i-1) + dt * f2;
end
% Plot the concentration of u and v for the current a value
plot(t, u, ‘DisplayName’, [‘u(t), a = ‘, num2str(a)]);
plot(t, v, ‘–‘, ‘DisplayName’, [‘v(t), a = ‘, num2str(a)]);
end
%% Add labels, legend, and grid to the plot
xlabel(‘Time (s)’);
ylabel(‘Concentration’);
title(‘Dynamics of u and v over Time for Different a Values’);
legend(‘show’);
grid on;
hold off; For the following activator-inhibitor system (Alfred Gierer-Hans Meinhardt model),
with all constants positive and initial conditions , examine the effect of the parameters () on the behavior of concentrations . Initially, we have to consider .
My problem is that I don’t undestand how to choose the right parameters every time. For example but the code works and for or but when I chose you can see below, the results are not correct.
Could anyone explain please? Thanks in advance
Parameter k : Range: 0.01 to 1
% Define common parameters
P = 0.75; % Production rate of u
a = 1; % rate of u inhibition by v
b = 0.9; % Production rate of v stimulated by u
mu = 0.5; % Decay rate of u
ks = [0.01, 0.1, 1];
T = 10; % Total simulation time
dt = 0.01; % Time step
t = 0:dt:T; % Time vector
% Initial conditions
u0 = 1; % Initial concentration of u
v0 = 0.5; % Initial concentration of v
%% Initialize a figure
figure(1);
hold on
%% Loop through each k value
for k = ks
N = length(t); % Number of time steps
% Initialize arrays for u and v
u = zeros(1, N);
v = zeros(1, N);
% Set initial conditions
u(1) = u0;
v(1) = v0;
% Simulate the system’s response
for i = 2:N
% Calculate the changes in u and v using the system equations
f1 = P – a * (u(i-1)^2 / v(i-1)) – mu * u(i-1); % Change in activator
f2 = b * u(i-1)^2 – k * v(i-1); % Change in inhibitor
% Update u and v using Euler’s method
u(i) = u(i-1) + dt * f1;
v(i) = v(i-1) + dt * f2;
end
% Plot the concentration of u and v for the current k value
plot(t, u, ‘DisplayName’, [‘u(t), k = ‘, num2str(k)]);
plot(t, v, ‘–‘, ‘DisplayName’, [‘v(t), k = ‘, num2str(k)]);
end
%% Add labels, legend, and grid to the plot
xlabel(‘Time (s)’);
ylabel(‘Concentration’);
title(‘Dynamics of u and v over Time for Different k Values’);
legend(‘show’);
grid on;
hold off;
Parameter : Range: 0.01 to 1
% Define common parameters
P = 0.75; % Production rate of u
a = 1; % Rate of u inhibition by v
b = 0.9; % Production rate of v stimulated by u
k = 1; % Decay rate of v (fixed in this scenario)
mus = [0.01, 0.1, 9]; % Different decay rates of u to test
T = 10; % Total simulation time
dt = 0.01; % Time step
t = 0:dt:T; % Time vector
% Initial conditions
u0 = 1; % Initial concentration of u
v0 = 0.5; % Initial concentration of v
%% Initialize a figure
figure(2);
hold on
%% Loop through each mu value
for mu = mus
N = length(t); % Number of time steps
% Initialize arrays for u and v
u = zeros(1, N);
v = zeros(1, N);
% Set initial conditions
u(1) = u0;
v(1) = v0;
% Simulate the system’s response
for i = 2:N
% Calculate the changes in u and v using the system equations
f1 = P – a * (u(i-1)^2 / v(i-1)) – mu * u(i-1); % Change in activator
f2 = b * u(i-1)^2 – k * v(i-1); % Change in inhibitor
% Update u and v using Euler’s method
u(i) = u(i-1) + dt * f1;
v(i) = v(i-1) + dt * f2;
end
% Plot the concentration of u and v for the current mu value
plot(t, u, ‘DisplayName’, [‘u(t), mu = ‘, num2str(mu)]);
plot(t, v, ‘–‘, ‘DisplayName’, [‘v(t), mu = ‘, num2str(mu)]);
end
%% Add labels, legend, and grid to the plot
xlabel(‘Time (s)’);
ylabel(‘Concentration’);
title(‘Dynamics of u and v over Time for Different mu Values’);
legend(‘show’);
grid on;
hold off;
Parameter b : Range: 0.01 to 10
% Define common parameters
P = 0.75; % Production rate of u
a = 1; % Rate of u inhibition by v
mu = 0.5; % Decay rate of u
k = 1; % Decay rate of v
bs = [0.1, 1, 9.9]; % Different rates for b to test
T = 10; % Total simulation time
dt = 0.01; % Time step
t = 0:dt:T; % Time vector
% Initial conditions
u0 = 1; % Initial concentration of u
v0 = 0.5; % Initial concentration of v
%% Initialize a figure
figure(3);
hold on
%% Loop through each b value
for b = bs
N = length(t); % Number of time steps
% Initialize arrays for u and v
u = zeros(1, N);
v = zeros(1, N);
% Set initial conditions
u(1) = u0;
v(1) = v0;
% Simulate the system’s response
for i = 2:N
% Calculate the changes in u and v using the system equations
f1 = P – a * (u(i-1)^2 / v(i-1)) – mu * u(i-1); % Change in activator
f2 = b * u(i-1)^2 – k * v(i-1); % Change in inhibitor
% Update u and v using Euler’s method
u(i) = u(i-1) + dt * f1;
v(i) = v(i-1) + dt * f2;
end
% Plot the concentration of u and v for the current b value
plot(t, u, ‘DisplayName’, [‘u(t), b = ‘, num2str(b)]);
plot(t, v, ‘–‘, ‘DisplayName’, [‘v(t), b = ‘, num2str(b)]);
end
%% Add labels, legend, and grid to the plot
xlabel(‘Time (s)’);
ylabel(‘Concentration’);
title(‘Dynamics of u and v over Time for Different b Values’);
legend(‘show’);
grid on;
hold off;
Parameter a : Range: 0.1 to 10
% Define common parameters
P = 0.75; % Production rate of u
b = 0.9; % Production rate of v stimulated by u
mu = 0.5; % Decay rate of u
k = 1; % Decay rate of v (constant in this scenario)
as = [0.1, 1, 9.9]; % Different rates of a to test
T = 10; % Total simulation time
dt = 0.01; % Time step
t = 0:dt:T; % Time vector
% Initial conditions
u0 = 1; % Initial concentration of u
v0 = 0.5; % Initial concentration of v
%% Initialize a figure
figure(4);
hold on
%% Loop through each a value
for a = as
N = length(t); % Number of time steps
% Initialize arrays for u and v
u = zeros(1, N);
v = zeros(1, N);
% Set initial conditions
u(1) = u0;
v(1) = v0;
% Simulate the system’s response
for i = 2:N
% Calculate the changes in u and v using the system equations
f1 = P – a * (u(i-1)^2 / v(i-1)) – mu * u(i-1); % Change in activator
f2 = b * u(i-1)^2 – k * v(i-1); % Change in inhibitor
% Update u and v using Euler’s method
u(i) = u(i-1) + dt * f1;
v(i) = v(i-1) + dt * f2;
end
% Plot the concentration of u and v for the current a value
plot(t, u, ‘DisplayName’, [‘u(t), a = ‘, num2str(a)]);
plot(t, v, ‘–‘, ‘DisplayName’, [‘v(t), a = ‘, num2str(a)]);
end
%% Add labels, legend, and grid to the plot
xlabel(‘Time (s)’);
ylabel(‘Concentration’);
title(‘Dynamics of u and v over Time for Different a Values’);
legend(‘show’);
grid on;
hold off; model, mathematics, differential equations, plot, plotting, homework MATLAB Answers — New Questions
What license I need ?
I use MATLAB for preparing journal publications. I have no benifits from these publications.I use MATLAB for preparing journal publications. I have no benifits from these publications. I use MATLAB for preparing journal publications. I have no benifits from these publications. journal publication MATLAB Answers — New Questions
Use Retime of a timetable to interpolate to timestamps of another timetable, without interpolating across NaNs
I am trying to interpolate values within one timetable to the timestamps in another timetable. However, I do not want to interpolate across gaps where NaNs exist, which occurs when using the standard retime function.I am trying to interpolate values within one timetable to the timestamps in another timetable. However, I do not want to interpolate across gaps where NaNs exist, which occurs when using the standard retime function. I am trying to interpolate values within one timetable to the timestamps in another timetable. However, I do not want to interpolate across gaps where NaNs exist, which occurs when using the standard retime function. retime, omit nan, interpolation MATLAB Answers — New Questions
error using saveas in fig format
Hellow Dear,
I tried to save a figure using saveas in fig format and I got several error messages. Saving the same figure in other format such as jpg is fine.
% plot
for page = 1: num_page
if ci_end(page) > numel(screened_contact)
ci_end(page) = numel(screened_contact);
end
figure(page), clf
sgtitle(‘ Compare orig vs interpolated stim artifact in data pre-processing’)
pageF = nrow_subp*ncol_subp*(page -1); % factor to compensate subplot# after page1
for ci = ci_begin(page) : ci_end(page)
subplot(nrow_subp, ncol_subp, ci-pageF), hold on
%grayColor = [.7 .7 .7];
plot(timevec, ref_EP(ci, :), ‘k’, "LineWidth", 1)
plot(timevec, prepro_EP(ci, :), ‘r’, "LineWidth", 1)
title( strjoin([num2str(ci) ‘, C’ num2str(screened_contact(ci)) ‘, ‘ region(ci) ‘, ‘ region_abbrev(ci)]) )
plot([0 0], get(gca,’ylim’), ‘k–‘, ‘linewidth’,1)
plot(get(gca,’xlim’) ,[0 0], ‘k–‘,’linewidth’, 1)
%yvalue = max([max(abs(ref_EP(ci,[1:900]))) max(abs(prepro_EP(ci,[1:900]))) ]);
%set(gca, ‘ylim’, [-1 1]* (yvalue+20))
%set(gca,’xtick’,[-0.1 0 0.2 0.4])
%set(gca, ‘xticklabels’, [-0.1 0 0.2 0.4])
set(gca, ‘xlim’, [-0.1 0.4])
end
set(gcf, ‘Position’, get(0, ‘Screensize’));
saveas(figure(1), [ char(output(1,:)) ‘preprocessed_vs_ref_con’ num2str(ci_begin(page)) ‘_to_’ num2str(ci_end(page)) ‘.fig’ ])
saveas(figure(1), [ char(output(1,:)) ‘preprocessed_vs_ref_con’ num2str(ci_begin(page)) ‘_to_’ num2str(ci_end(page)) ‘.jpg’ ])
close(1)
endHellow Dear,
I tried to save a figure using saveas in fig format and I got several error messages. Saving the same figure in other format such as jpg is fine.
% plot
for page = 1: num_page
if ci_end(page) > numel(screened_contact)
ci_end(page) = numel(screened_contact);
end
figure(page), clf
sgtitle(‘ Compare orig vs interpolated stim artifact in data pre-processing’)
pageF = nrow_subp*ncol_subp*(page -1); % factor to compensate subplot# after page1
for ci = ci_begin(page) : ci_end(page)
subplot(nrow_subp, ncol_subp, ci-pageF), hold on
%grayColor = [.7 .7 .7];
plot(timevec, ref_EP(ci, :), ‘k’, "LineWidth", 1)
plot(timevec, prepro_EP(ci, :), ‘r’, "LineWidth", 1)
title( strjoin([num2str(ci) ‘, C’ num2str(screened_contact(ci)) ‘, ‘ region(ci) ‘, ‘ region_abbrev(ci)]) )
plot([0 0], get(gca,’ylim’), ‘k–‘, ‘linewidth’,1)
plot(get(gca,’xlim’) ,[0 0], ‘k–‘,’linewidth’, 1)
%yvalue = max([max(abs(ref_EP(ci,[1:900]))) max(abs(prepro_EP(ci,[1:900]))) ]);
%set(gca, ‘ylim’, [-1 1]* (yvalue+20))
%set(gca,’xtick’,[-0.1 0 0.2 0.4])
%set(gca, ‘xticklabels’, [-0.1 0 0.2 0.4])
set(gca, ‘xlim’, [-0.1 0.4])
end
set(gcf, ‘Position’, get(0, ‘Screensize’));
saveas(figure(1), [ char(output(1,:)) ‘preprocessed_vs_ref_con’ num2str(ci_begin(page)) ‘_to_’ num2str(ci_end(page)) ‘.fig’ ])
saveas(figure(1), [ char(output(1,:)) ‘preprocessed_vs_ref_con’ num2str(ci_begin(page)) ‘_to_’ num2str(ci_end(page)) ‘.jpg’ ])
close(1)
end Hellow Dear,
I tried to save a figure using saveas in fig format and I got several error messages. Saving the same figure in other format such as jpg is fine.
% plot
for page = 1: num_page
if ci_end(page) > numel(screened_contact)
ci_end(page) = numel(screened_contact);
end
figure(page), clf
sgtitle(‘ Compare orig vs interpolated stim artifact in data pre-processing’)
pageF = nrow_subp*ncol_subp*(page -1); % factor to compensate subplot# after page1
for ci = ci_begin(page) : ci_end(page)
subplot(nrow_subp, ncol_subp, ci-pageF), hold on
%grayColor = [.7 .7 .7];
plot(timevec, ref_EP(ci, :), ‘k’, "LineWidth", 1)
plot(timevec, prepro_EP(ci, :), ‘r’, "LineWidth", 1)
title( strjoin([num2str(ci) ‘, C’ num2str(screened_contact(ci)) ‘, ‘ region(ci) ‘, ‘ region_abbrev(ci)]) )
plot([0 0], get(gca,’ylim’), ‘k–‘, ‘linewidth’,1)
plot(get(gca,’xlim’) ,[0 0], ‘k–‘,’linewidth’, 1)
%yvalue = max([max(abs(ref_EP(ci,[1:900]))) max(abs(prepro_EP(ci,[1:900]))) ]);
%set(gca, ‘ylim’, [-1 1]* (yvalue+20))
%set(gca,’xtick’,[-0.1 0 0.2 0.4])
%set(gca, ‘xticklabels’, [-0.1 0 0.2 0.4])
set(gca, ‘xlim’, [-0.1 0.4])
end
set(gcf, ‘Position’, get(0, ‘Screensize’));
saveas(figure(1), [ char(output(1,:)) ‘preprocessed_vs_ref_con’ num2str(ci_begin(page)) ‘_to_’ num2str(ci_end(page)) ‘.fig’ ])
saveas(figure(1), [ char(output(1,:)) ‘preprocessed_vs_ref_con’ num2str(ci_begin(page)) ‘_to_’ num2str(ci_end(page)) ‘.jpg’ ])
close(1)
end saveas, fig MATLAB Answers — New Questions
Avoid overlapping different graphs that are placed in the same positions
Hello, I’m currently trying to plot two graphs in App Designer at the same position. They keep overlapping themselves and I’m not sure how to fix this issue. When I do "hold on" and "hold off", it opens another window where the graphs are shown. Is there any way to acheive this?Hello, I’m currently trying to plot two graphs in App Designer at the same position. They keep overlapping themselves and I’m not sure how to fix this issue. When I do "hold on" and "hold off", it opens another window where the graphs are shown. Is there any way to acheive this? Hello, I’m currently trying to plot two graphs in App Designer at the same position. They keep overlapping themselves and I’m not sure how to fix this issue. When I do "hold on" and "hold off", it opens another window where the graphs are shown. Is there any way to acheive this? appdesigner, graphs, geoplot MATLAB Answers — New Questions
clear all output code
Is it possible in matlab live script to "clear all output" with a program code?Is it possible in matlab live script to "clear all output" with a program code? Is it possible in matlab live script to "clear all output" with a program code? clear_all_output MATLAB Answers — New Questions
obtaining heart rate from ECG signal
Hello,
I need to obtain heart rate values from an ECG signal. While searching for information, I discovered that I need to (more or less) get the RR interval and then use the time difference between samples to calculate the instantaneous HR.
I have a database acquired in the local hospital, but the raw signal is full of noise and invalid samples but I dont know how to remove both.
Attached you can find of the raw ECG. It is sampled at 1kHz, stored in int16 data type and the measured units are milivolts.
fl = fopen("ficheroAnalogico.dat");
A = fread(fl, inf, ‘int16’);
fclose(fl);
figure(1)
subplot(3,1,1);
plot(A);
title(‘raw’);
subplot(3,1,2);
plot(A_4000);
title(‘zoom’);
I use this short code to read the data and plot it, but, as you can see in the capute, the data is full of noise and invalid samples.
The second plot show the first 4000 samples, where you can see the R peaks, but I need to filter and remove invalid samples before calculating HR. Can you please help me? I know I’m asking for too much, but I haven’t programmed in more than 10 years, so my knowlegde is rusted and I’m really stucked.
Thanks you in advance and sorry for my english.
DanielHello,
I need to obtain heart rate values from an ECG signal. While searching for information, I discovered that I need to (more or less) get the RR interval and then use the time difference between samples to calculate the instantaneous HR.
I have a database acquired in the local hospital, but the raw signal is full of noise and invalid samples but I dont know how to remove both.
Attached you can find of the raw ECG. It is sampled at 1kHz, stored in int16 data type and the measured units are milivolts.
fl = fopen("ficheroAnalogico.dat");
A = fread(fl, inf, ‘int16’);
fclose(fl);
figure(1)
subplot(3,1,1);
plot(A);
title(‘raw’);
subplot(3,1,2);
plot(A_4000);
title(‘zoom’);
I use this short code to read the data and plot it, but, as you can see in the capute, the data is full of noise and invalid samples.
The second plot show the first 4000 samples, where you can see the R peaks, but I need to filter and remove invalid samples before calculating HR. Can you please help me? I know I’m asking for too much, but I haven’t programmed in more than 10 years, so my knowlegde is rusted and I’m really stucked.
Thanks you in advance and sorry for my english.
Daniel Hello,
I need to obtain heart rate values from an ECG signal. While searching for information, I discovered that I need to (more or less) get the RR interval and then use the time difference between samples to calculate the instantaneous HR.
I have a database acquired in the local hospital, but the raw signal is full of noise and invalid samples but I dont know how to remove both.
Attached you can find of the raw ECG. It is sampled at 1kHz, stored in int16 data type and the measured units are milivolts.
fl = fopen("ficheroAnalogico.dat");
A = fread(fl, inf, ‘int16’);
fclose(fl);
figure(1)
subplot(3,1,1);
plot(A);
title(‘raw’);
subplot(3,1,2);
plot(A_4000);
title(‘zoom’);
I use this short code to read the data and plot it, but, as you can see in the capute, the data is full of noise and invalid samples.
The second plot show the first 4000 samples, where you can see the R peaks, but I need to filter and remove invalid samples before calculating HR. Can you please help me? I know I’m asking for too much, but I haven’t programmed in more than 10 years, so my knowlegde is rusted and I’m really stucked.
Thanks you in advance and sorry for my english.
Daniel matlab, heart rate, ecg, intervalrr MATLAB Answers — New Questions