https://www.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions2021-04-11T19:51:12Ztag:www.mathworks.com,2005:Question/7719082021-03-13T18:47:56Z2021-04-11T19:51:12ZReinforcement Learning Onramp IssueI am working on this task and doing exactly what it says, even the solution has the same code for Task 3. I am not sure what I am missing. Could someone explain this pelase? Thank you!
Nahid Hasan Tusharhttps://www.mathworks.com/matlabcentral/profile/authors/7344640tag:www.mathworks.com,2005:Question/7991472021-04-11T19:50:16Z2021-04-11T19:50:16Z3D Scatterplot and Pareto Front visualizationHey,
So first things first, I'm really new in MatLab and even though I'm trying to learn the bassics in order to do what I want and udenrstand it, it seems like it is hard when you are under schedule.
I've Uploaded an excel file with all my data ( 525 rows and 3 columns) and then I created my workspace. After that I defined my x's,y's and z's using the following commands.
numbers = xlsread(filename);
x = numbers(1:525,3);
y = numbers(1:525,2);
z = numbers(1:525,1);
I tried following this answer ( https://www.mathworks.com/matlabcentral/answers/110723-is-it-possible-to-generate-surface-pareto-front-for-3-objective-functions-and-plot-it) but I had no luck - the first reason was because I couldn'y understand what a,b and c were and how they were related to my data.
So my question is, how do I create a 3d scatterplot were I can also create a visible Pareto front?
Thanks in advance!Apostolos Fragkalashttps://www.mathworks.com/matlabcentral/profile/authors/22137277tag:www.mathworks.com,2005:Question/4318082018-11-25T12:45:01Z2021-04-11T19:46:52Zdrawing a function graph. Find the stationary points of the function and examine the quality of the functiondrawing a function graph. Find the stationary points of the function and examine the quality of the function:
im sure i can draw the function but how do i find the stationary points?Gaston Gakomohttps://www.mathworks.com/matlabcentral/profile/authors/12474209tag:www.mathworks.com,2005:Question/7991422021-04-11T19:43:19Z2021-04-11T19:43:19ZHow can I model a sequencing batch reactor in Matlab?Hi, I have to model a sequencing batch reactor in Matlab, particularly the feed and the react phases.
As the feed phse is long enough, I have to model it taking into account both dilution with the influent and reactions which occur in the reactor. So, dilution is not istantaneous, and it must be occur together with dilution. I tried to model them one before each other, or also together (the latter calculating the average concentartion between diluted concentration and simulated concentration after reactions, with initial concentrations as initial condition).
However, the overall concentration trend I obtained along the entire feed phase is not the same as what I got using other simulation software, which I know they are correct.
Thank you for your answers!Elia Painihttps://www.mathworks.com/matlabcentral/profile/authors/7115132tag:www.mathworks.com,2005:Question/7988272021-04-11T13:24:14Z2021-04-11T19:42:51ZGoertzel Algorithm for calculating amplitude and angleHello everybody!
I have written a script that describes Goertzel Algorithm. The script is given below. The algorithm calculates correct real part but incorrect imaginary part of original signal. So how to receive the correct imaginary part?
Sampling frequency (N) & nominal frequency (f) with simulation interval (t) are given as:
N = 80; % points/period
f = 50; % Hz
t = 0.02; % s
Time array is:
TimeArray = 0:1/f/N:t;
Original signal array is equal:
x = cos(2*pi*f*TimeArray);
The first part of Goertzel Algorithm is given below.
% W - z^-1
% H(z) = ---------------------------
% 1 - alpha * z^-1 + z^-2
%
% W = W_N^(-k) = exp(2i*pi*k/N).
% alpha = 2*cos(2*pi*k/N).
k = 50; % Spectral sample number
om = 2*pi*k/N;
w = exp(-1i*om);
%alpha
alpha = 2*cos(om);
s1 = 0; s2 = 0;
for h7 = 1:length(x)
s0 = alpha * s1 - s2 + x (h7);
s2 = s1;
s1 = s0;
end
The second part of Goertzel Algorithm is Xk. Xk is the algorithm output. Here Xk gives out complex number. However Xk gives me correct real and incorrect imaginary of complex number.
Xk = s1 - w * s2;Ismoil Odinaevhttps://www.mathworks.com/matlabcentral/profile/authors/18248867tag:www.mathworks.com,2005:Question/7983872021-04-10T19:31:54Z2021-04-11T19:38:02ZApp designer - problem with thresholding imageHi folks,
I have the app attached, in which I am encountering two issues. Firstly, when trying to threshold an image and displaying the thresholded image, it would appear my function calls aren't working as the image displayed is not thresholded. (ResinThreshold function works in live editor, but not when called in app designer). The thresholding function is below.
Thanks
function ResinThreshold(app)
imgGrey = rgb2gray(app.img);
[counts, ~] = imhist(imgGrey, 255);
T = otsuthresh(counts);
BW = imbinarize(imgGrey, T);
BW = bwareaopen(BW, 3000);
BW = imfill(BW, 'holes');
BW = bwperim(BW);
BW = imdilate(BW, ones(5));
BW = imerode(BW, ones(3));
BW = imfill(BW, 'holes');
app.img = app.img.*repmat(uint8(BW),[1 1 3]);
end Teshan Rezelhttps://www.mathworks.com/matlabcentral/profile/authors/17128181tag:www.mathworks.com,2005:Question/7991222021-04-11T19:07:09Z2021-04-11T19:36:16Z My plot comes up as a white graph with no line.My homework is like that,
This is about dynamic voltage stability, I can't code this equation. After that I eliminate T, because it is constant, then just calculate PR. I want to draw t,PR and t,VR graph. But i can't. Please help me.
This question says Vr changes 1-0.9-1-1.05-1 respectively. then calculate Pr for T=1 and T<1,T>1.
Thank you from now.
When I try to plot with this code which is given below, nothing comes up. There are no errors, there's just nothing. I know, I only asking to draw one point at a time, so the plot has no information about which points should be connected. But i am new at Matlab, i can't able to draw graphic, please help me.
Expected graphic is like that,
clear all;
clc;
G=3;
t1=1:5
VR1=1;
PR1=G*VR1^2;
t2=5:15
VR2=0.9;
PR2=G*VR2^2;
t3=15:25;
VR3=1;
PR3=G*VR3^2;
t4=25:35;
VR4=1.05;
PR4=G*VR4^2;
t5=35:40;
VR5=1;
PR5=G*VR5^2;
hold on, plot(t1,VR1)
plot(t2,VR2)
plot(t3,VR3)
plot(t4,VR4)
plot(t5,VR5)
xlabel('t(1/100)'); ylabel('VR');
title('PR Değişimi');
grid on
Yunus Mercanhttps://www.mathworks.com/matlabcentral/profile/authors/19983468tag:www.mathworks.com,2005:Question/7878692021-03-30T11:35:16Z2021-04-11T19:29:33ZHow do i remove or disable or hide zoom in zoom out, save, brush tool from Matlab figures ?
How do i remove zoom in zomm out, save brush tool from matlab figures, because it appear in publishing flies and cannot be removed.GAURAV BAKHRUhttps://www.mathworks.com/matlabcentral/profile/authors/20602548tag:www.mathworks.com,2005:Question/7991172021-04-11T18:48:58Z2021-04-11T19:22:44ZConversion From Gray scale to RGB colormapHello, I am trying to convert images from gray scale to RGB. Firstly, I tried it for the jet colormap, but I would like to do this for other possible colormaps which MATLAB has. I imported the 'car1.jpg' image and converted via these lines:
indexedImage = imread('car1.jpg');
Gray_Image= indexedImage(:,:,1)*0.299+indexedImage(:,:,2)*0.587+indexedImage(:,:,3)*0.114;
Then I gave "Gray_Image" variable to my function "gray_to_jet" to convert RGB. Although output seemed like "jet", there are differences between MATLAB's jet colormap. How can I exactly map the values like MATLAB? I am new to image processing, so any help including theoritical appreciated. Here is my function:
function [converted_image,Elapsed_time] = gray_to_jet(varargin)
input_image = varargin{1};
[row_number, column_number] = size(input_image);
C = uint8(255*colormap('jet')); % Convert 0-1 numbers in colormap to 0-255 and uint8.
converted_image = zeros(row_number, column_number, 3);
for idx = 1:row_number
for jdx =1:column_number
colormap_row= double(input_image(idx, jdx) ) + 1;
new_red_pixel = C(colormap_row, 1);
new_green_pixel = C(colormap_row, 2);
new_blue_pixel = C(colormap_row, 3);
converted_image(idx, jdx, 1) = new_red_pixel;
converted_image(idx, jdx, 2) = new_green_pixel;
converted_image(idx, jdx, 3) = new_blue_pixel;
end
end
endBerkay Yaldizhttps://www.mathworks.com/matlabcentral/profile/authors/10491148tag:www.mathworks.com,2005:Question/7988122021-04-11T12:48:36Z2021-04-11T19:17:42ZHow to stop blue highlighting of UITables created in app designer on cell selectionHow do I prevent uitables from hightlighting the cells when I click on them?
I do not want to disable uitables because that would grey out the uitable.Kelvin Lhttps://www.mathworks.com/matlabcentral/profile/authors/17026776tag:www.mathworks.com,2005:Question/7991322021-04-11T19:17:17Z2021-04-11T19:17:17Zproblems with rapid accelerator modelWhen I try to compile Rapid accelerator model, I get this:
Unable to build a standalone executable to simulate the model 'exp1' in rapid accelerator mode.
Caused by:
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance Please download a supported version of Xcode at /Applications/MATLAB_R2019b.app/rtw/c/tools/macsdkver.pl line 24. xcrun clang -arch x86_64 -isysroot /Library/Developer/CommandLineTools/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -mmacosx-version-min=10.9 -c -fno-common -fexceptions -DTGTCONN -DON_TARGET_WAIT_FOR_START=0 -DRSIM_PARAMETER_LOADING -O0 -DEXT_MODE -DIS_RAPID_ACCEL -DMODEL=exp1 -DHAVESTDIO -DUNIX -DNRT -DRSIM_WITH_SL_SOLVER -DENABLE_SLEXEC_SSBRIDGE=1 -DMODEL_HAS_DYNAMICALLY_LOADED_SFCNS=0 -I. -I../../.. -I/Users/derpy/work/Matlab/Group2 -I/Users/derpy/work/Matlab/Group2/slprj/raccel/exp1 -I/Applications/MATLAB_R2019b.app/extern/include -I/Applications/MATLAB_R2019b.app/simulink/include -I/Applications/MATLAB_R2019b.app/rtw/c/src -I/Applications/MATLAB_R2019b.app/rtw/c/src/rapid -I/Applications/MATLAB_R2019b.app/rtw/c/raccel -I/Applications/MATLAB_R2019b.app/rtw/c/src/ext_mode/common -I/Applications/MATLAB_R2019b.app/toolbox/coder/rtiostream/src -I/Applications/MATLAB_R2019b.app/toolbox/coder/rtiostream/src/rtiostreamtcpip -I/Applications/MATLAB_R2019b.app/toolbox/coder/rtiostream/src/utils /Applications/MATLAB_R2019b.app/rtw/c/src/rt_logging.c clang: warning: no such sysroot directory: '/Library/Developer/CommandLineTools/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk' [-Wmissing-sysroot] /Applications/MATLAB_R2019b.app/rtw/c/src/rt_logging.c:21:10: fatal error: 'stdlib.h' file not found #include <stdlib.h> ^~~~~~~~~~ 1 error generated. gmake: *** [rt_logging.o] Error 1
Why does it happen? One week ago it compiles properly.
Matlab 2019b, MacOS 10.14.6, Xcode 11.3 (11C29)Semion Kurochkinhttps://www.mathworks.com/matlabcentral/profile/authors/9824285tag:www.mathworks.com,2005:Question/7989772021-04-11T16:26:43Z2021-04-11T19:14:45ZBrace indexing is not supported for variables of this type.How do I call the sort_nat function to sort folders?
clear all
clc
PF = 'D:\Project\DB1\test\' % Parent Folder
SFL = dir(PF) ;% List the sub folders
[mp1, np] = size(SFL); % compute size = number of subfolders & files & . & ..
csf1=0; % counter of JUST subfolders found in PF
t=1;
for i=3:mp1
%% keep only folders:
P = strfind(SFL(i).name,'.');
if isempty(strfind(SFL(i).name,'.'))
csf1 = csf1 +1; % one sub folder found
SFN = SFL(i).name ;% extract his name
%-----
[SFN,index]= sort_nat(SFN);
c1 = [SFN,index];
%---------------
tifList = ls(sprintf('%s%s%s%s',PF,c1,'\','*.tif')); % list all jpg files
[ms1, ns] = size(tifList); % ms = number of image files found
%% Processing for each tif file:
for j=1:ms1
tifFileName = tifList(j,:); % extract name of tif file
Group_Test1(t)=[i-2]
t=t+1;
% PF_SFN_imgName = sprintf('%s%s%s',PF,SFN,'\',tifFileName);
end
end
end
save('Group_Test','Group_Test1');sun risehttps://www.mathworks.com/matlabcentral/profile/authors/16482360tag:www.mathworks.com,2005:Question/7989272021-04-11T15:18:25Z2021-04-11T19:14:24ZBinomial Distribution when mean and variance is givenHow do i plot a Binomial Distribution when i have been given its mean and variance for example like mean = 3, variance = 3 or 0.5,2.......these values dont satisfy the conditions for mean and variance which are mean should lie between 0 and 1 and variance should be less than mean(mean - 1)...But these are the values i have to find the binomial distribution for...this is code i have written....
mu = 3;
var = 3;
alpha = (((1-mu)/var)-1/mu).*mu^2;
beta = alpha((1/mu) - 1);
X = 0:0.01:1;
Y = betapdf(X,alpha,beta);
%plot(X,Y,'LineWidth',1);
xlabel('Thetha');
hold on
mu2 = 0.5;
var2 =2 ;
alpha2 = (((1-mu2)/var2)-1/mu2).*mu2^2;
beta2 = alpha2((1/mu2) - 1);
X2 = 0:0.01:1;
Y2 = betapdf(X2,alpha2,beta2);
plot(X2,Y2,'LineWidth',1);
hold off;Soham Bastehttps://www.mathworks.com/matlabcentral/profile/authors/19215162tag:www.mathworks.com,2005:Question/7991272021-04-11T19:12:09Z2021-04-11T19:12:09ZHow to define nested function?I want to define this f fucntion
f = @(x,y)((2.*x+y).*(x<d & y<d)+ (3.*x.*y-1).*(x>d & y<d)+...
(1+x+y).*(x<d & y>d)+ (3.*x+2.*y).*(x>d & y>d)+ ((2.*x(N/2)+y)+...
(3.*x(N/2+2).*y-1)/2).*(x==d & y<d) + (((2.*x+y(N/2))+...
(1+x+y(N/2+2)))/2).*(y==d & x<d)+(((1+x(N/2)+y)+...
(3.*x(N/2+2)+2.*y))/2).*(x==d & y>d)+(((3.*x.*y(N/2)-1)+...
(3.*x+2.*y(N/2+2)))/2).*(y==d & x>d)+(((2.*x(N/2)+y(N/2))+...
(3.*x(N/2+2).*y(N/2)-1)+(1+x(N/2)+y(N/2+2))+(3.*x(N/2+2)+...
2.*y(N/2+2)))/4).*(x==d &y==d));
If i define like this, I am getting error which is mentioned below
Error using
trying1>@(x,y)((2.*x+y).*(x<d&y<d)+(3.*x.*y-1).*(x>d&y<d)+(1+x+y).*(x<d&y>d)+(3.*x+2.*y).*(x>d&y>d)+((2.*x(N/2)+y)+(3.*x(N/2+2).*y-1)/2).*(x==d&y<d)+(((2.*x+y(N/2))+(1+x+y(N/2+2)))/2).*(y==d&x<d)+(((1+x(N/2)+y)+(3.*x(N/2+2)+2.*y))/2).*(x==d&y>d)+(((3.*x.*y(N/2)-1)+(3.*x+2.*y(N/2+2)))/2).*(y==d&x>d)+(((2.*x(N/2)+y(N/2))+(3.*x(N/2+2).*y(N/2)-1)+(1+x(N/2)+y(N/2+2))+(3.*x(N/2+2)+2.*y(N/2+2)))/4).*(x==d&y==d))
Too many input arguments.
Please help me to correct it. Thanks in advance.
Aarthika Balakumarhttps://www.mathworks.com/matlabcentral/profile/authors/22006786tag:www.mathworks.com,2005:Question/7991022021-04-11T18:21:55Z2021-04-11T19:07:55ZImage Segmentation - Watershed AlgorithmI have followed the very helpful instructions on Steve Eddin's blog post concerning image segmentation of cells using the watershed algorithm. I have one piece to fine tune in my own image that I am working on. There are small sections in the cluster of cells in the top right corner where the algorithm produces segments for what should be the background. Can anyone suggest any strategies for resolving this? I am providing my code, the input image and my annotated output image showing the sections I would like to relegate to the background region.
Input image (b&w), output image (rgb); arrows point to sections I am trying to address.:
function A = getArea(I)
level = graythresh(I);
bw = imbinarize(I,level);
%did not use imfill because this fills in area separating cells
%bw = imfill(bw,'holes');
bw3 = imopen(bw,ones(5,5));
bw4 = bwareaopen(bw3,40);
mask_em = imextendedmax(I,30);
I_c = imcomplement(I);
I_mod = imimposemin(I_c, ~bw4 | mask_em);
L = watershed(I_mod);
imshow(label2rgb(L));
endRebecca Schleyhttps://www.mathworks.com/matlabcentral/profile/authors/21410978tag:www.mathworks.com,2005:Question/7988822021-04-11T14:34:41Z2021-04-11T19:04:47Z display of the intensity curve of the pointshello everyone, I use this code to select points :
IM=imread('capture.jpg');
imshow(IM);
impixelinfo;
[xi,yi]=getpts
I want after the selection of the points, display a curve which contains the intensity of each pointAmal Felhihttps://www.mathworks.com/matlabcentral/profile/authors/22103929tag:www.mathworks.com,2005:Question/7983822021-04-10T19:26:34Z2021-04-11T18:59:15ZApp designer - deleting an unnamed plotHi folks,
I have the following code for generating 1 or multiple plots on an image.
function ROI(app, index1, index2)
hold (app.Image, "on")
plot(app.Image, index1, index2, app.innerMarkerStyle, 'LineWidth', app.CrosshairThickness.Value, 'Color', app.crossHairColour, 'MarkerSize', app.CrosshairRadius.Value);
plot(app.Image, index1, index2, app.outerMarkerStyle, 'LineWidth', app.CrosshairThickness.Value, 'Color', app.crossHairColour, 'MarkerSize', app.CrosshairRadius.Value);
end
My question is, suppose there are 3 such plots. Is there a way to delete 1 and only 1 of them selectively?
Thanks Teshan Rezelhttps://www.mathworks.com/matlabcentral/profile/authors/17128181tag:www.mathworks.com,2005:Question/7990672021-04-11T17:53:25Z2021-04-11T18:57:54ZError using corrplot functionHi,
I try to plot the correlation between two variables, but I keep getting a error:
Undefined function 'corrplot' for input arguments of type 'double'.
The code I used was:
corrplot(KNMIGlobalestraling2018,DataHourlyTable.DataTableCorrect2)
How can I fix this?Quincy Brouwerhttps://www.mathworks.com/matlabcentral/profile/authors/21481692tag:www.mathworks.com,2005:Question/7989922021-04-11T16:46:38Z2021-04-11T18:50:20Zhow can i sort excel file data of 2nd column of 1 row after that 430 row ,860 row,1290 row and so on mean column is fix but row increased by 430, all the values are numerical?how can i sort excel file data of 2nd column of 1 row after that 430 row ,860 row,1290 row and so on mean column is fix but row increased by 430, all the values are numerical?shivali atrehttps://www.mathworks.com/matlabcentral/profile/authors/2631660tag:www.mathworks.com,2005:Question/7990872021-04-11T18:14:13Z2021-04-11T18:48:02ZLogistic Growth Model - Code and PlotI need to plot a differential equation that shows logistic growth. The equation is: P=(K*A*e^r*t)/(1+A*e^r*t)
where K is the carrying capacity, a constant, and K = 1,704,885 and A = 0.0122.
I need the correct code so that I can solve for r, as well as put different t to find the population at varying times.
I also need to plot the solution. Thank you for any help!Emma Hadleyhttps://www.mathworks.com/matlabcentral/profile/authors/21243913tag:www.mathworks.com,2005:Question/7990572021-04-11T17:43:13Z2021-04-11T18:45:18ZHow to find the nearby sampling stationsI have millions of samping sations, my goal is to find the nearby stations with a certain distance threshold. What is the best way to do it based on the longitude and latitude information?
It seems that calculating the stations between each of them is extremely time-consuming.
Thanks.
Leonhttps://www.mathworks.com/matlabcentral/profile/authors/3133287tag:www.mathworks.com,2005:Question/7990072021-04-11T16:51:06Z2021-04-11T18:44:11Zgaussian regarding random variableswhat would be the pictorial difference of PDFs of X1 and Y = X1- X2 where X1 and X2 are gaussian random variables. I am getting error in the code. can someone please help me . Kinjal Agarwalhttps://www.mathworks.com/matlabcentral/profile/authors/19215341tag:www.mathworks.com,2005:Question/7991122021-04-11T18:24:09Z2021-04-11T18:42:43ZPlease change this code from inline to function.clear all
clc
format short
f1=inline('2*x.^3+y.^3+x.*y-6');
f2=inline('x.^3-y.^3+x.*y-4;');
clear i
X0=[i 1+i]; X1=[-i i-2]; X2=[i+1 1];
for k=1:21
M=[X0 1; X1 1; X2 1];
v=[f1(X0(1),X0(2)); f1(X1(1),X1(2)); f1(X2(1),X2(2))];
c1=M\v;
v=[f2(X0(1),X0(2)); f2(X1(1),X1(2)); f2(X2(1),X2(2))];
c2=M\v;
c=[c1';c2'];
X=-c(1:2,1:2)\c(:,3);
X0=X1; X1=X2; X2=X';
end지원 안https://www.mathworks.com/matlabcentral/profile/authors/21640167tag:www.mathworks.com,2005:Question/7990172021-04-11T17:02:53Z2021-04-11T18:39:42Zvolumeofsphere matlab function need helpI put 10^4 into the function and I should be expecting Number of points inside sphere to be 3 and the area should be 0.0024. Am I missing something if so what do I need to change ?
function volumeofsphere3(n)
ds = RandStream.getGlobalStream;
reset(ds);
x=2*rand(n,1);
y=rand(n,1);
z=rand(n,1);
count=0
for i=1:n
r=sqrt((x(i)-1/3)^2+(y(i)-1/3)^2+(z(i)-1/2)^2);
if r<=0.04
count=count+1;
end
end
fprintf(1,'Number of points inside sphere: %d\n', count)
Area_of_Sphere=8*(count/n)
end gracias claudehttps://www.mathworks.com/matlabcentral/profile/authors/21366237tag:www.mathworks.com,2005:Question/7988072021-04-11T12:36:25Z2021-04-11T18:36:47ZTrouble solving ODE equationsI am trying to solve these differential equations in order to plot graphs, however, when running the code I am receiving multiple errors but I'm unsure why as I can't see why the code is not running smoothly? I'm looking for some insight on why this might be happening and how I can solve the problem?
Equations and Parameter values:
function dydt = Dunster(t,y)
%Parameters and their values%
K1a = 20;
Y1a = 1;
K1b = 0.25;
K2a = 14;
K2am = 72;
K2b = 2.6;
K2bm = 10;
K2c = 24;
K2cm = 20;
K3a = 10;
K3b = 0.05;
K3c = 24;
K3cm = 20;
K4a = 2.3;
K4am = 58;
K4b = 2000;
K4bm = 210;
K4c = 1.3;
K5a = 0.0014;
K5b = 0.35;
K6 = 2000;
K6m = 2000;
Kx = 50;
Kb = 0.01;
Lb = 1;
Lx = 1;
Bxva = 0;
H = K1a*Y1a*exp(-Y1a*t);
bl = 0.5*((Kb+Lb+Bxva)-sqrt((Kb+Lb+Bxva)^2 - 4*Lb*Bxva));
%Equation 1%
%Generation and inactivation of factor Xa%
F1= y(1);
%y(1)= -K6*F1;
% Factor I
%Equation 2%
F5=y(2);
%y(2)=(-K2a*F2a*F5)/(F5+K2am(1+F1/K6m) - ((K2b*F10a*F5)/F5+K2bm(1+F2/K4am)));
%Equation 3%
F2=y(3);
%y(3)= ((-K4a*F1*F2)/F2+K4am(1+F5/K2bm))-((K4b*b1*F2)/(F2+K4bm));
%Equation 4%
C=y(4);
%y(4)= (-K5a*C);
%Equation 5%
F10a=y(5);
%y(5)= H +(K3c*Ca*Bxva)/(Bxva+K3cm) - K1b*F10a - K3a*F10a*F5a;
%Equation 6%
F5a=y(6);
%y(6)= (K2a*F2a*F5)/(F5+K2am(1+F1/K6m)) + (K2b*F10a*F5a)/(F5+K2bm(1+F1/K4am))+ K3b*Bxva - (K2c*Ca*F5a)/(F5a+K2am) - K3a*F10a*F5a;
%Equation 7%
Bxva=y(7);
%y(7)= K3a*F10a*F5a - K3b*Bxva - (K3c*Ca*Bxva)/(Bxva+K3cm);
%Equation 8%
F2a=y(8);
%y(8)= (K4a*F1*F2)/(F2+K4am(1+F5/K2bm)) + (K4b*BF2)/(F2+K4bm) - K4c*F2a;
%Equation 9%
Ca=y(9);
%y(9)= K5a*C - K5b*Ca;
%Equation 10%
F10i=y(10);
%y(10)= K1b*F10a + K3b*Bxva;
%Equation 11%
F5i=y(11);
%y(11) = (K2c*Ca*F5a)/(F5a+K2cm) + (K3c*Ca*Bxva/(Bxva+K3cm));
%Equation 12%
F2i=y(12);
%y(12) = K4c*F2a;
%Equation 13%
Ci=y(13);
%y(13) = K5b*Ca;
%Equation 14%
F1a=y(14);
%y(14) = K6*F1;
dydt=[
-K6*F1; % d F1 / dt
((-K2a*F2a*F5)/(F5+K2am*(1+F1/K6m)) - ((K2b*F10a*F5)/F5+K2bm*(1+F2/K4am))); % d F5 / dt
((-K4a*F1*F2)/(F2+K4am*(1+F5/K2bm))-((K4b*bl*F2)/(F2+K4bm))); % d F2 / dt
-K5a*C; % d C / dt
H+(K3c*Ca*Bxva)/(Bxva+K3cm) - K1b*F10a - K3a*F10a*F5a ;
% d F10a / dt
(K2a*F2a*F5)/(F5+K2am(1+F1/K6m)) + (K2b*F10a*F5a)/(F5+K2bm(1+F1/K4am))
+ K3b*Bxva - (K2c*Ca*F5a)/(F5a+K2am) - K3a*F10a*F5a; % d F5a / dt
K3a*F10a*F5a - K3b*Bxva - (K3c*Ca*Bxva)/(Bxva+K3cm); % d Bxva / dt
(K4a*F1*F2)/(F2+K4am(1+F5/K2bm)) + (K4b*BF2)/(F2+K4bm) - K4c*F2a ;
% d F2a / dt
K5a*C - K5b*Ca ; % d Ca / dt
K1b*F10a + K3b*Bxva ; % d F10i / dt
((K2c*Ca*F5a)/(F5a+K2cm) + (K3c*Ca*Bxva/(Bxva+K3cm))) ; % d F5i / dt
K4c*F2a ; % d F2i / dt
K5b*Ca ; % d Ci / dt
K6*F1 ; % d F1a / dt
];
end
Running Part of the Code:
tspan=[0 60];
F1=10000;
F5=30;
F2=1000;
C=100;
F10a=0;
F5a=0;
Bxva=0;
F2a=0;
Ca=0;
F10i=0;
F5i=0;
F2i=0;
Ci=0;
F1a=0;
y0=[F1;F5;F2;C;F10a;F5a;Bxva;F2a;Ca;F10i;F5i;F2i;Ci;F1a];
[t,y]=ode45(@Dunster, tspan, y0);%,[], pars);
plot(t/60, y(:,14)*1000, "r")
xlabel("Time [Min]")
ylabel("Concentration [nM]")
Jack Mulrooneyhttps://www.mathworks.com/matlabcentral/profile/authors/20657737tag:www.mathworks.com,2005:Question/7464372021-02-16T02:48:58Z2021-04-11T18:35:00ZHow to correctly use MONTHS function?I am trying to find the difference between dates in "months". I have refferred to the following documentation on usage of "months" function and I even tried out the example given in the documentation but all I get is an error.
https://in.mathworks.com/help/finance/months.html
Code: MyMonths = months('may 31 2000', 'jun 30 2000', 1)
Error: Check for missing argument or incorrect argument data type in call to function 'months'.
What am I missing?Namrata Goswamihttps://www.mathworks.com/matlabcentral/profile/authors/20826718tag:www.mathworks.com,2005:Question/7985922021-04-11T04:39:29Z2021-04-11T18:34:58ZSymbolic printing without extensive decimals syms x
f=x*1231871.1561876*5618965/3156651894-561894+4849159*15844/5189;
l=vpa(x*1231871.1561876*5618965/3156651894-561894+4849159*15844/5189);
fprintf('%s\n',f)
fprintf('%s\n',l)
(1351321833700369665875*x)/616259847708475392 + 7647426328677875/536870912
2192.7792938728320167173931401797*x + 14244441.555212950333952903747559
I am trying to get my problem to print more efficiently, I have tried the vpa tool, and it works nicely, but I have no customization (as far as im aware) as to how to control the number of decimal places on the polynomial that is being printed using these commands while having a symbolic function/polynomial.
How can I tidy up this so that it prints in an easier to read format, with, for example, 5 decimal places rather than the amount it has?Ramses Younghttps://www.mathworks.com/matlabcentral/profile/authors/22161720tag:www.mathworks.com,2005:Question/7991072021-04-11T18:22:19Z2021-04-11T18:22:19ZBus elements with multiple dimensionsI have a structure S with three time series fields a, b and a.
S.a = timeseries
S.b = timeseries
S.c = timeseries
I'd like to create a bus object (B) with above bus element. But instead of creating 3 bus elements (a, b and c) I'd like to create one bus element (S) with dimention of 3. I created the bus B like this:
S = Simulink.BusElement;
S.Name = 'S';
S.Dimensions = 3;
B = Simulink.Bus;
B.Elements = S;
How can I assing (sub)bus elements (a, b and c) to S (and B)?
Alborz Sakhaeihttps://www.mathworks.com/matlabcentral/profile/authors/21653044tag:www.mathworks.com,2005:Question/7990972021-04-11T18:15:37Z2021-04-11T18:21:51ZIndex a Matrix that gets smallerI have a cell array that I am deleting any rows with empty values, and while indexing I run into the error:
"Index in position 1 exceeds array bounds (must not exceed 347)."
Here is the script for the part that has the issue, how can I index a cell array while deleting stuff as it goes?
for ind=2:size(RAW)
if sum(strcmp('',RAW(ind,4:7)))~=0
RAW(ind,:)=[]
end
end
note: I am skipping the first row intentionally, and also only checking columns 4 through 7Bryson Princehttps://www.mathworks.com/matlabcentral/profile/authors/21088507tag:www.mathworks.com,2005:Question/7990472021-04-11T17:37:24Z2021-04-11T18:20:23Zhs923a function for Monte Carlo ApproxI found this function online and getting an error when using halton. Has the function changed in Matlab if so what do I use now ?
function hs923a(n)
x=2*halton(2,n)-1;
y=2*halton(3,n)-1;
count=1;
for i=1:n
if x(i)>=-1
if y(i)<=1
if 13*(x(i)^2)+34*x(i)*y(i)+25*y(i)^2 <= 1
count=count+1;
end
end
end
end
disp(['Number of points inside the ellipse =', num2str(4*count)])
endgracias claudehttps://www.mathworks.com/matlabcentral/profile/authors/21366237tag:www.mathworks.com,2005:Question/7990922021-04-11T18:15:00Z2021-04-11T18:15:00ZCan I track how often and who have viewed the shared channel of mine for a day or a month if I shared my private channels with others on ThingSpeak or ThingView? Thanks in advance.Jaewoo Leehttps://www.mathworks.com/matlabcentral/profile/authors/22166734tag:www.mathworks.com,2005:Question/7990422021-04-11T17:36:35Z2021-04-11T18:12:59ZHow to convert arc length to km?My goal is to find a good function to calculate the distance for two points for millions of data points. I found the fucntion lldistkm in the FileExchange. Unfortunately, that function does not seem to work well for column data. It only works well for single data points.
Lon1 = -78.1982;
Lat1 = 33.8282;
Lon2 = -77.5003;
Lat2 = 32.8499;
Distance_km = lldistkm([Lat1, Lon1],[Lat2, Lon2])
Distance_arc = distance(Lat1, Lon1, Lat2, Lon2)
Here is my question. If I will rely on the Matlab function distance (see above) in the mapping toolbox to calcualte the distance. It's results will be in arc length? How do I convert it from arc length to km? Their ratio should be around 111 depending on the latitude.
So rad2km is the wrong function? It does not give me a number close to 111 at all.
Many thanks.
Leonhttps://www.mathworks.com/matlabcentral/profile/authors/3133287tag:www.mathworks.com,2005:Question/7990372021-04-11T17:32:12Z2021-04-11T18:11:19Z2 digits after the dotHi
In the following example where do I put: ,'%0.2f'
x = [1 2 3];
vals = [2 3.3333333 6; 11 23 26];
b = bar(x,vals);
xtips1 = b(1).XEndPoints;
ytips1 = b(1).YEndPoints;
labels1 = string(b(1).YData);
text(xtips1,ytips1,labels1,'HorizontalAlignment','center','VerticalAlignment','bottom')
xtips2 = b(2).XEndPoints;
ytips2 = b(2).YEndPoints;
labels2 = string(b(2).YData);
text(xtips2,ytips2,labels2,'HorizontalAlignment','center','VerticalAlignment','bottom')
Same problem here:
x = 0:pi/100:2*pi;
y = sin(x);
plot(x,y)
my_num= 3.33333
text_information =['my num is : ' num2str((my_num))];
xlabel(text_information); xlabel(text_information,'interpreter','latex')
tnx :)Shahar ben ezrahttps://www.mathworks.com/matlabcentral/profile/authors/17813425tag:www.mathworks.com,2005:Question/7990722021-04-11T17:58:38Z2021-04-11T18:10:20Zplotting logarithmic and linear scaleI'm working on an assignment that wants me to create a .m file that graphs both the linear and logarithmic scale.
The assignment is:
I have the script doing exactly what I need it to for the linear scale plot, however, I'm not sure how to also get matlab to transition it to log scale for the second set of plots. any help would be useful.
The code I have so far is:
t=linspace(0,20,1000);
speed=188.5*(1-exp(-0.4*t));
torque=10*exp(-0.4*t);
power=torque.*speed;
figure(1)
subplot(3,1,1)
plot(t,torque,'r-','LineWidth',2)
title('\bfPlot of Motor Output Torque\bf\it\tau\rm\bf_{IND},Speed\bf\it\omega_{m},and Power\bf\itP vs Time')
ylabel('\bf\itTorque, \tau\rm\bf_{IND}(N-m)')
grid on
subplot(3,1,2)
plot(t,speed,'r-','LineWidth',2)
ylabel('\bf\itSpeed, \omega_{m}\rm\bf(rad/s)')
grid on
subplot(3,1,3)
plot(t,power,'r-','LineWidth',2)
xlabel('\bfTime,t[s]')
ylabel('\bf\itPower, P\rm\bf(watts)')
grid on
the plots of the log scale should look like this:
Brendan Clarkhttps://www.mathworks.com/matlabcentral/profile/authors/21223451tag:www.mathworks.com,2005:Question/7964422021-04-08T15:15:36Z2021-04-11T18:09:31ZRead date and version number from txt file via regular expressionHi,
my task is to read version of software and date of the usage from a log file.
Version number appears on a row like this:
Version 2.85;
and date on a row like:
Date of elaboration : 26-Mar-2021 12:54:25;
I'm able to split the txt file that contains the log onto rows, i only need to extract "2.85" and "26-Mar-2021" via Regular expressions.
Thanks for your time,
AlessandroAlessandro Tognihttps://www.mathworks.com/matlabcentral/profile/authors/20843104tag:www.mathworks.com,2005:Question/7990822021-04-11T18:05:13Z2021-04-11T18:05:13ZThermal modelling of a photovoltaic module in simulinkHello,
I am a master student and have a question for the community. I should create a thermal model of a photovoltaic module in simulink. I'd be glad if I can contact someone who already created one before and help me. I haven't used simulink before.metin elginhttps://www.mathworks.com/matlabcentral/profile/authors/21248163tag:www.mathworks.com,2005:Question/7990772021-04-11T18:03:53Z2021-04-11T18:03:53ZConnecting jetson nano with PixhawkI have been trying to connect the Jetson nano device to Pixhawk to obtain the roll, pitch and yaw values. I am following the instructions as per the link https://www.mathworks.com/help/supportpkg/jetsoncpu/ref/jetson-pixhawk-interface-example.html?searchHighlight=jetsoncpuLib&s_tid=srchtitle. Currenlty, I am stuck at the task 4(of the link provided) which is to perform monitor and tune. The yaw, pitch and roll value changes during tune under the target model, but not running during the simulation of the Jetson Pixhawk Interface Host model and gives error.
Dhruvil Vekariyahttps://www.mathworks.com/matlabcentral/profile/authors/17369502tag:www.mathworks.com,2005:Question/7990622021-04-11T17:52:30Z2021-04-11T17:56:40ZFind baseline and sudden signal changes (as well as duration until return to baseline) for noisy dataI'm struggling with some data I extracted and hoping for some help on how to best deal with it. I have attached an example
The presumed baseline is marked in red. I have multiple consecutive events indicated by a sudden change in baseline and then becoming weaker over time before changing back to basline. I would need the length of such an event. How can I best determine the baseline and relaibly measure the lengths of these events. Hope someone can give me some directions
Lutetiumhttps://www.mathworks.com/matlabcentral/profile/authors/20037566tag:www.mathworks.com,2005:Question/7986022021-04-11T04:46:16Z2021-04-11T17:54:54Zwhy my plot is not correct?here is my code
x = -5:0.1:5
y = x.^(1/3)
plot(x,y)wenchong chenhttps://www.mathworks.com/matlabcentral/profile/authors/18123326tag:www.mathworks.com,2005:Question/7917292021-04-03T16:35:45Z2021-04-11T17:54:15ZCalculate diameter from a circle in an image in MATLAB
Hi,
I have to measure the diameter from a circle in a image and I don't quite know where to start.
I began by loading the image and turning it into a blacknwhite image.
img = imread (file);
labimg = rgb2lab(img);
Now I basically need my program to detect the circle and measure the diameter. and then plot it
I really hope someone could help me out
Thanks a lotsongül bagbarshttps://www.mathworks.com/matlabcentral/profile/authors/16602801tag:www.mathworks.com,2005:Question/7056832020-12-30T18:43:32Z2021-04-11T17:47:41ZVery slow graphics when mouse pointer moves around a figureI've got a little widget that animates a sequence of images by calling the "image()" function repeatedly with new images in a sequence. Normally the animation proceeds reasonably fast around 50-60 frames per second. However, if the mouse is in the figure window and moves around (not even clicking on anything), then the animation slows to a crawl (about 2-3 frames per second) as long as the mouse moves in the figure window. (See code at bottom for simple example to replicate this).
I've checked to ensure that the 'WindowButtonMotionFcn' figure callback is disabled (as are all other figure callbacks). I can't find any other figure, axes or even image objects that might be triggered by mouse motion in the figure window.
If I run the profiler and compare results with and without the mouse moving around the figure window, I see the function:
ToolbarController.ToolbarController>@(e.d)obj.handleMouseMotion
(and its dependent functions ) is getting called thousands of times and is consuming 90% of the runtime when the mouse is moving around I tried turning off both the figure's toolbar and the figure's menu bar, e.g:
hFigure.ToolBar = 'none';
hFigure.MenuBar = 'none';
and that slightly alleviates the issue somewhat, but not much (perhaps 10-20% better) . Further, even with the toolbars turned off, the profiler still indicates that
ToolbarController.ToolbarController>@obj.handleMouseMotion
is still consuming 90% of the run time whenever the mouse is moving around. There also is the function
AxesToolbarButton.AxesToolbarButton>AxesToolbarButton.AxesToolbarButton
that is also getting called thousands of times and is consuming some of the time. So I also disable the AxesToolbar by:
axesTB = get(hAxes,'ToolBar');
axesTB.visible = 'off';
axesTB.BusyAction = 'cancel';
(Unlike the figure toolbar, there doesn't seem a setting to completely disable a AxesToolbar). Anyway, turning off the axesTB didn't seem to help.
% This code can be used to illustrate the issue of slowly updating graphics.
% Run this, and then move the mouse around the figure window.
for loop=1:500
image(rand(300,300),'CDataMapping','scaled');
drawnow;
end
%Clearing the axes with "cla" before the image() call doesn't change the result. However, this version of the code is seemingly NOT impacted by this issue or very little:
hImg = image(rand(300,300),'CDataMapping','scaled');
for loop=1:500
hImg.CData = rand(300,300);
drawnow;
end
In the latter case, the profiler say that the function
ToolbarController.ToolbarController>@(e.d)obj.handleMouseMotion
still gets called a whole bunch of times but it ends up only consuming about 15% of the runtime (not 90+%), and the animation proceeds at 50+ FPS. So there is something about the combination of a moving mouse and creating new objects (rather than changing attributes of existing objects) that seems to grind matlab graphics to a halt. While I clearly point out a workaround for my little example above, in the general case, such workarounds are not always possible. It seems odd that moving a mouse while drawing objects in a figure shouldn't necessarily slow down things as much as it appears to do.
Thoughts appreciated.
Peterhttps://www.mathworks.com/matlabcentral/profile/authors/14174tag:www.mathworks.com,2005:Question/7987472021-04-11T10:51:26Z2021-04-11T17:46:59ZHow to change values to 3 decimal points and 7 significant figures?hi,
I am Matlab program beginner.
I came across a problem in which I want to change the decimal places and significant figues of the value I computed.
The values I get is
easting_northing =
1.0e+03 *
1.0000 1.0000
1.0635 0.9227
but actually I need the values to become like this form:
easting_northing =
1000.000 1000.000
1063.500 922.720
how to do that???
thank you in advanceLoh Yang Yauhttps://www.mathworks.com/matlabcentral/profile/authors/21964682tag:www.mathworks.com,2005:Question/7989672021-04-11T16:19:09Z2021-04-11T17:43:57Zplotting line graph in different colors using while loopI have a variable called "data" that's a set of data that's 49 rows x 40 columns. time is the first column (data(:,1)) and I want to plot time against the second column of the data (data(:,2)). When the the values in the second column are in certain ranges, I want the line of the line graph to be different colors. I wrote a while/ if else statement to do this, but it's not plotting anything and I'm not sure why. My code is written below. Thank you in advance!
figure
p = 1 %row that's changing (40 rows in all)
w = 2 %sensor/column number
hold on
while p <=size(data,1) %size of column
if data(p,w)<2.65
plot(data(p,1),data(p,2),'g')
elseif data(p,w)>=2.65 & data(p,w)<3.975
plot(data(p,1),data(p,2),'y')
else data(p,w)>=3.975
plot(data(p,1),data(p,2),'r')
end
p = p+1
end Lauren Yearyhttps://www.mathworks.com/matlabcentral/profile/authors/10832534tag:www.mathworks.com,2005:Question/7885292021-03-31T00:14:24Z2021-04-11T17:43:39ZWhy is my priceandvol chart not showing all the values? how do i label the price chart and the volume chart? how do i get dates on the price chart?clear
clc
walmart = xlsread('WMT_Daily_Returns3.xlsx');
dateconvert=x2mdate(walmart, 0, 'datetime');
priceandvol(walmart(:,2:end));
xlabel('Date')
ylabel('Volume')
dateaxis('X', 12, min(walmart(:,1)))
title('Walmart Stock Price and Volume')
legend('Volume of Shares')Matty O'Malleyhttps://www.mathworks.com/matlabcentral/profile/authors/21222395tag:www.mathworks.com,2005:Question/7990522021-04-11T17:42:43Z2021-04-11T17:42:43ZconfigurePlutoRadio('AD9364','usb:0') Command not workingI am trying to configure my new ADALM PLUTO SDR to the AD9364 configuration in order to be able to get the bigger frequency range. I want to receive signals at 150MHz which should be fine after using the >> configurePlutoRadio('AD9364','usb:0') command. I ran the command and it showed me that the configuration is successful. However, I still get an error about operating outside the factory default frequency range for the SDR and I get prompted to run the same command and I run it again but still get the same error. This is the error I keep on getting:
Failed to update LO for device: cf-ad9361-lpc. Specified center frequency is outside factory default range. To assign the center frequency to 150000000, release the radio and click configurePlutoRadio('AD9364','usb:0'). For more information, see help configurePlutoRadio.
Is the command outdated and does not work anymore or am I doing something wrong?
Looking forward for a reply. Thanks.rashed alhaj mohammadhttps://www.mathworks.com/matlabcentral/profile/authors/14859404tag:www.mathworks.com,2005:Question/7990322021-04-11T17:27:08Z2021-04-11T17:27:46ZSimulation of Shepp Logan phaton datasetWhat is the name of the method used for the simulation of Shepp Logan phantom having dimention 256x256 with number of coils=8.Ria khanhttps://www.mathworks.com/matlabcentral/profile/authors/22166896tag:www.mathworks.com,2005:Question/7990122021-04-11T16:52:27Z2021-04-11T17:25:55Zinterp1 question for resamplingI am trying to use interp1 to resample my data. I have the values of forces for different timeframe lengths. (eg. I have 4 trials, trial one has 36 frames, trial 2 has 43, trial 3 has 38, tria4 has 35). To compare them have a nice figure, I want to <<expand>> the number of frames to 100 for each of them (like it would be 1-100% of the timeframe).
I used resample in the beginning, but I get some noise in the beginning and the end of the signal.
dif_Fx = (resample(dif(1:motion_length,1),100,motion_length))
(motion_length is the number of frames and dif is my signal)
I tried to use interp1 as
dif_Fx = (interp1((dif(1:motion_length,1)),1:1:100));
dif_Fx is just the signal (dif), and the rest of the values, from motion_length+1 to 100 are NaN.
I have read again and again the documentation, but I can;t seem to understand how to modify it to get what I want.
Any help is much appreciated.
Andra Topanhttps://www.mathworks.com/matlabcentral/profile/authors/11249921tag:www.mathworks.com,2005:Question/7990272021-04-11T17:24:32Z2021-04-11T17:24:32ZMethod for Shepp Logan Phantom What is the method used to estimate Shepp logan dataset of size 256x256 with 8 number of coils.Ria khanhttps://www.mathworks.com/matlabcentral/profile/authors/22166896tag:www.mathworks.com,2005:Question/4654442019-06-04T08:50:00Z2021-04-11T17:21:33ZPlease write the code for this question.Given a Matrix A,
Create a row vector of 1's that has same number of elements as A has rows.
Create a column vector of 1's that has the same number of elements as A has columns.
Using matrix multiplication, assign the product of the row vector, the matrix A, and the column vector (in this order) to the variable result.
A = [1:5; 6:10; 11:15; 16:20];Gaurav Srivastavahttps://www.mathworks.com/matlabcentral/profile/authors/13163632tag:www.mathworks.com,2005:Question/7990222021-04-11T17:19:28Z2021-04-11T17:19:28ZMATLAB program for the design of Chebyshev digital low pass filter using Write a MATLAB program for the design of Chebyshev digital low pass filter using the following specification:
0.9 ≤│H(ejw)│≤ 1 0 ≤ w ≤ 0.3π
│H(ejw)│≤ 0.15 0.5π ≤ w ≤ π Nishant khttps://www.mathworks.com/matlabcentral/profile/authors/20964689