https://it.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions2020-06-02T22:57:47Ztag:it.mathworks.com,2005:Question/5409322020-06-02T22:37:39Z2020-06-02T22:57:47ZRounding error when dividingI realized when dividng two small numbers, there is a rounding error that occurs.
For instance, if I do a series of calculations that eventually leave me with the numbers:
a = 5.669896651707230e-10
b = 1.417474162926808e-10
If I do a/b in the command window, the result will be ans = 4
Why doesn't MATLAB give me the decimal places?
I've tried both typecasting to double before dividing, and multiplying a and b by 1e10 before dividing, but all yield the same results, with the answer being an integer.
The numbers I am manipulating appear to have many digits after the decimal if I examine the workspace.
I manipulate the variables directly from the workspace, and do not input the numbers numerically (if you input the variables as stated above and do the division, the rounding error will not occur, but there will be a rounding error when pulling these values from the workspace).
How could I fix this and get the precision I need?
I've appended the actual code that this example pertains to below:
h = logspace(0,-25,100);
% Initialization
fxch = zeros(2,length(h));
dfdx = zeros(2,length(h));
% Operations
% Fun is just a function with two inputs
fxch(1,:) = Fun(-8+1i*h,-8);
dfdx(1,:) = imag(fxch(1,:))./h;
% The problem is that dfdx returns a mix of floating point numbers and integers
% where I need all elements of dfdx to be floats.Eric Kimhttps://it.mathworks.com/matlabcentral/profile/authors/13335234-eric-kimtag:it.mathworks.com,2005:Question/5409262020-06-02T22:22:02Z2020-06-02T22:54:41ZOutput standard deviation and Mean When i run my programme, how do i only output the fprintf values?
function [VSD,M] = mean_stdev(A)
A=input('N numbers:')
% This function calculates the mean and standard deviation without
% using in-built functions
som=0;
for i=1:length(A)
som=som+A(i);
end
M=som/length(A) %the mean
fprintf('Mean is: %f\n', M)
moy=0;
for i=1:length(A)
moy = (A(i)- M)^2;
moy = (moy)/length(A);
end
VSD=sqrt(moy/length(A)) %Varaince
fprintf('stadard dev: %f\n',VSD)
end
The output
>> mean_stdev
N numbers:
[5 6 7 8]
A =
5 6 7 8
M =
6.5000
Mean is: 6.500000
VSD =
0.3750
stadard dev: 0.375000
ans =
0.3750
>> Christopher Clarkehttps://it.mathworks.com/matlabcentral/profile/authors/17994937-christopher-clarketag:it.mathworks.com,2005:Question/5401512020-06-02T03:58:00Z2020-06-02T22:52:01ZHow can I get the metrics of newly added defects at command line using any of polyspace tools?Hello,
I've been using Polyspace tools specially polyspace-configure, polyspace-bug-finder, polyspace-results-repository to run bug finder and upload results. I want to get info on number of defects newly added in the polyspace results repository in latest upload; Is there a way or possibility to get this info from command line by running any of the polyspace tools?
Thank you, Appreciate your support.
SivSivaram Prasad Nakkalahttps://it.mathworks.com/matlabcentral/profile/authors/17385935-sivaram-prasad-nakkalatag:it.mathworks.com,2005:Question/5362792020-05-28T08:12:23Z2020-06-02T22:47:24ZImport comments written in Polyspace AccessHello,
I´m starting to use Polyspace Access in a continuous integration workflow and want to know when and how comments which have been set at Polyspace Access are integrated into the created reports. At earlier versions I used the "import comments" function where the last result was checked to integrate all comments which were identified as unchanged. Is that option set by default at Polyspace Server usage or only available if I set it actively in the options file together with the result directory? And where does it take the old result from? Is it also downloaded from the configuration management system?
Another related question is if it is possible to trigger a new report creation after adding comments to the finding manually? Or does the software developer need to wait for the next automatic run until the report is updated?
Thank you and best regards,
BirgitBirgit Roithnerhttps://it.mathworks.com/matlabcentral/profile/authors/9693405-birgit-roithnertag:it.mathworks.com,2005:Question/811482013-07-04T17:32:40Z2020-06-02T22:44:41ZGet path from running scriptGreetings!
I know that this is a bit hackneyed, but I couldn't get a working solution.
I run a script (not function) saved as m-file. Now I want to get path to the m-file from inside the script.
Widely suggested *mfilename('fullpath')* returns nothing, because it should be called from a function (but not from script).
Can you suggest a viable solution please?
Thank you!Andrey Kazakhttps://it.mathworks.com/matlabcentral/profile/authors/604883-andrey-kazaktag:it.mathworks.com,2005:Question/5408992020-06-02T21:11:37Z2020-06-02T22:42:39ZWhy do I get Inf for this complex expression?
I have a function that generates a complex number but I get Inf for x. how could this be, if I do not make a logical error
for f=1:100
%a and b are struct passed by value, e.g. sturct(1).field
[R1,R2] = Prop(a(f),b(f),f,constant(f))
{e1=cell2mat(a)+cell2mat(b);
e2=cell2mat(a)-cell2mat(b);
w=(1-e1.*e2)./(e1-e2);}
endDaniel Montgomeryhttps://it.mathworks.com/matlabcentral/profile/authors/13306603-daniel-montgomerytag:it.mathworks.com,2005:Question/5408902020-06-02T21:08:46Z2020-06-02T22:41:08Zhex2dec return error>> hex2dec(238a)
hex2dec(238a)
↑
Error: Invalid expression. Check for missing multiplication operator, missing or unbalanced
delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.
Jimmy Zhaohttps://it.mathworks.com/matlabcentral/profile/authors/17794761-jimmy-zhaotag:it.mathworks.com,2005:Question/3027282016-09-12T08:09:31Z2020-06-02T22:39:59ZI am looking for LEACH-C protocol source code in MATLAB ?can any one help me in getting the source code of LEACH_C protcolAbdelwahab Fawzyhttps://it.mathworks.com/matlabcentral/profile/authors/6561729-abdelwahab-fawzytag:it.mathworks.com,2005:Question/5409382020-06-02T22:38:13Z2020-06-02T22:38:13ZHow to add a colorbar in a heatmap? Hey guys!
I am trying to do a heatmap, using a the heatmap function. But I am not being capable of adding a colorbar. Does anyone know if it is possible using the MATLAB version 2016a?
Also my current heatmap is like this, I would like to invert the beggining of the rows position. Is it possible that the row number 1 start on the first line not in the last one? And how could I eliminate the elements above the main diagonal?
Thnkss
Julia Moorehttps://it.mathworks.com/matlabcentral/profile/authors/17927402-julia-mooretag:it.mathworks.com,2005:Question/5409352020-06-02T22:37:55Z2020-06-02T22:37:55ZHow to add a colorbar in a heatmap? Hey guys!
I am trying to do a heatmap, using a the heatmap function. But I am not being capable of adding a colorbar. Does anyone know if it is possible using the MATLAB version 2016a?
Also my current heatmap is like this, I would like to invert the beggining of the rows position. Is it possible that the row number 1 start on the first line not in the last one? And how could I eliminate the elements above the main diagonal?
Thnkss
Julia Moorehttps://it.mathworks.com/matlabcentral/profile/authors/17927402-julia-mooretag:it.mathworks.com,2005:Question/5409232020-06-02T22:21:19Z2020-06-02T22:36:50ZArray indices must be positive integers or logical values.I keep getting the error "Array indices must be positive integers or logical values" on every equation within the for loop and I'm not sure what I'm doing wrong. I've looked through other posts with this error and I can't seem to find my error
clear
clc
% Set known variables
rho = 800; % kg/m^3
mu = 0.00035; % N*s/m^2
Q = 2; % m^3/s
n = 25; % unitless
g = 9.81; % m/s^2
L = 160934; % m
m_dot = rho*Q;
H = L/(m_dot*g);
D = 1:0.1:10;
for n = 1:length(D)
P(D) = (128*mu*(Q^2)*L)./(pi*(D.^4));
CQ(D) = (P)./(rho*(n^3)*(D.^5));
CH(D) = (g*H)./((n^2)*(D.^2));
CQ(D) = Q./(n*(D.^3));
endCamille Molsick-Gibsonhttps://it.mathworks.com/matlabcentral/profile/authors/11001765-camille-molsick-gibsontag:it.mathworks.com,2005:Question/5408152020-06-02T18:43:46Z2020-06-02T22:36:42ZIssue with gammainc(x,a) for small x and larger aHi,
I've been having some trouble with the gammainc(x,a) function.
When x = 0.01 and a = 100, MATLAB says gammainc(x,a) = 0.
However, it should equal approx. 1e-358 (according to wolfram alpha).
How can I keep the precision in the value that close to zero?
Thank you!John Fullertonhttps://it.mathworks.com/matlabcentral/profile/authors/13883420-john-fullertontag:it.mathworks.com,2005:Question/5400312020-06-01T20:48:47Z2020-06-02T22:36:03ZCounting Total Number of Pixels by Color in a Segmented ImageHello I have mutiple segmented images that I would like to count the number of white, red, and blue pixels in each image using a for loop. I would like to store the number of red, white, and blue pixels associated with each image in an array along with the filename of each image. I can do each image manually, but I would like to make the process faster. I count the black pixels to make sure that the sum total of pixels assigned is close to 90,000, since each image is 300x300 and some pixels might be hard to distguinsh. Any help would be greatly appreicated. Thanks
rgbImage = imread('BioM Edge 576 Gen 5 Infl Rnge Start Segmented.png');
%rgbImage = imread('BioM Edge 576 Gen 10 Infl Rnge Start Segmented.png');
%rgbImage = imread('BioM Edge 576 Gen 15 Infl Rnge Start Segmented.png');
%rgbImage = imread('BioM Edge 576 Gen 20 Infl Rnge Start Segmented.png');
%rgbImage = imread('BioM Edge 576 Gen 25 Infl Rnge Start Segmented.png');
%rgbImage = imread('BioM Edge 576 Gen 30 Infl Rnge Start Segmented.png');
%%
BluePixels = rgbImage(:,:,1) == 0 & rgbImage(:,:,2) == 0 & rgbImage(:,:,3) == 255;
numBluePixels = sum(BluePixels(:));
%%
RedPixels = rgbImage(:,:,1) == 255 & rgbImage(:,:,2) == 0 & rgbImage(:,:,3) == 0;
numRedPixels = sum(RedPixels(:));
%%
WhitePixels = rgbImage(:,:,1) == 255 & rgbImage(:,:,2) == 255 & rgbImage(:,:,3) == 255;
numWhitePixels = sum(WhitePixels(:));
%%
BlackPixels = rgbImage(:,:,1) == 0 & rgbImage(:,:,2) == 0 & rgbImage(:,:,3) == 0;
numBlackPixels = sum(BlackPixels(:));
Vance Blakehttps://it.mathworks.com/matlabcentral/profile/authors/15947118-vance-blaketag:it.mathworks.com,2005:Question/3787522018-01-24T12:28:55Z2020-06-02T22:34:43ZDelete specific rows on a large matrix?Hello everyone,
I need some help, on a problem which looked pretty basic at the beginning. I have a very big matrix with 10947479 rows and 3 columns. But I don't need the values above 200 and it should remove the whole row. I tried like below:
idx = V1(:,2) >= 200;
V1(idx,:) = [];
Unfortunatly, the result is very bad. In the matrix are zeros now, while in the original matrix are none zeros at all. If I run the code like this:
V1(idx(1:10000),:) = [];
it works as supposed. I don't no why :(
Does anyone know how I can solve my problem?An Kuhttps://it.mathworks.com/matlabcentral/profile/authors/11287703-an-kutag:it.mathworks.com,2005:Question/5409292020-06-02T22:28:57Z2020-06-02T22:28:57ZSimulink Data Inspector waveform artifacts for large datasetWhen looking at large portions of a waveform in the Simulink Data Inspector, the waveform graphics have a tendency to create artifacts and effectively "skip" data points if zoomed out enough.
I'm not sure if this is a memory or drawing issue, but I haven't been able to find an option that seems to affect it.
Here are two screen captures with one only slightly more zoomed out in time than the other - you can see that the drawing begins to skip lots of points instead of drawing the full waveform.
Is there a way to change this behavior and get waveforms to draw, and if necessary to reduce the number of datapoints to do a decimation across the entire dataset?
Steven Lovelesshttps://it.mathworks.com/matlabcentral/profile/authors/13777422-steven-lovelesstag:it.mathworks.com,2005:Question/5409082020-06-02T21:26:15Z2020-06-02T22:22:05ZConfusion on Meshgrid and interp2 So i have x and y coordinates and i need to create sample points for the x and y coordinates to be evaluated at. I must use interp2 on these points in order to graph them.
I thought it would look something like this.
x = -0.5:0.1:0.5;
y = -0.5:0.1:0.5;
k = 0.77;
[x,y] = meshgrid(x,y);
z = k*(x.^2-y.^2);
m = [-0.5 0 0.5];
n = [-0.5 -0.25 0.25 0.5];
[m,n] = meshgrid(m,n);
f = interp2(x,y,z,m,n);
surf(x,y,f)
I am confused on where to go from here any help would be greatly appreciated.Michael Lynchhttps://it.mathworks.com/matlabcentral/profile/authors/17998186-michael-lynchtag:it.mathworks.com,2005:Question/5399552020-06-01T18:47:34Z2020-06-02T22:22:03ZI can solve the following question on paper but I want to do it using Matlab. How should I do that? I’ve attached the question and its solution.the question:
Link for hand solution: https://www.slader.com/discussion/question/consider-the-evaluation-of-ynx1nx2nx3n-where-x1n05n-un-x2nun3-and-x3n/
Ive been trying for a day to do a)evaluate the convolution of x1(n) *x2(n) and here is what i came up with and it has the following error
Invalid data type. First and second arguments must be numeric or logical.
clc;
clear
close all;
%u(n)
syms n;
u(n) = piecewise(n < 0,0,n>0, 1);
n = linspace(-20, 20, 500);
plot(n, u(n));
axis([-20 20 -2 2])
grid;
%x1
syms n
x1(n)= (0.5)^n *u(n)
n = linspace(-20, 20, 500);
plot(n,x1(n))
axis([-20 20 -1 1])
grid;
%x2
syms n
x2(n)= u(n + 3);
n= linspace(-20, 20, 500);
plot(n,x2(n))
axis([-20 20 -2 2])
grid;
%conv
syms n
n= linspace(-20, 20, 500);
z(n) = conv(x1(n),x2(n))
thnk you for your time.Youssef Moussahttps://it.mathworks.com/matlabcentral/profile/authors/18436846-youssef-moussatag:it.mathworks.com,2005:Question/5409202020-06-02T22:02:27Z2020-06-02T22:19:35Zhow to create incrementing arrays from each row of a matrix?I have a big table starts like this
A B
33 17
30 -4
26 14
25 14
I would like to get a new array containing the increments of the form (B:A) from each of the rows.
For instance (table.B(1):table.A(1)), (table.B(2):tableA(2)) and so on.
Is there a simple way to do this? Is a loop necessary?
Thank youJavier Cabellohttps://it.mathworks.com/matlabcentral/profile/authors/10429266-javier-cabellotag:it.mathworks.com,2005:Question/4379952019-01-02T19:16:23Z2020-06-02T22:18:22ZCalculating K factor of a rice distributionCan anyone help me with the significance of this rule: K factor = (A^2/2*sigma^2)
What does A stand for? and what does sigma stand for ?
I have a data set that follows a rice distribution and I want to calculate its K factor, How Can I apply this rule to my case? thank uyusra Chhttps://it.mathworks.com/matlabcentral/profile/authors/8951940-yusra-chtag:it.mathworks.com,2005:Question/5408872020-06-02T20:56:12Z2020-06-02T22:05:50ZHow to calculate derivative of function of inside of another function ?I can calculate g(-2) but I can not calculate g'(-2) at the same time with g(2). How can I write a function to calculate both of them in one function.
Hasan Berke Bankogluhttps://it.mathworks.com/matlabcentral/profile/authors/18133772-hasan-berke-bankoglutag:it.mathworks.com,2005:Question/5404072020-06-02T10:45:12Z2020-06-02T21:55:37ZFitting data with different type regressionHi.
I have got some data in form of x and y. I have plotted these data in logarithmic scale. Now i want to use two regeression line. one in form of y = c and another in form of
y = beta*(x)^alpha. a sample of this work is shown below:
And my plot data is like this (my data is attached):
could someone help me in this problem?
mohammadreza zaghiyanhttps://it.mathworks.com/matlabcentral/profile/authors/18668618-mohammadreza-zaghiyantag:it.mathworks.com,2005:Question/5408062020-06-02T18:27:53Z2020-06-02T21:52:05Zhow to change the pixel value for each of a list of pixelsHi,
I have a list of pixel's coordinates of 3D binary image (the list's dim: number of pixels to change x 3: the first column is the 'X' coordinate, the second is the 'Y' cooridinate and the third is 'Z' coordinate).
I would like to change each pixel in that list to hold the value of '0' (black color). how can I do it so it won't take too much time?
code examples would be appreciated! :)YAhttps://it.mathworks.com/matlabcentral/profile/authors/15841877-yatag:it.mathworks.com,2005:Question/5366072020-05-28T15:17:43Z2020-06-02T21:50:43Zhow to estimate paramters. I am try to estimate parameters using the following matlab code. it keep giving me this message below.
Error using ==> lsqncommon at 101
LSQCURVEFIT cannot continue because user supplied objective function failed with the following error:
Undefined function or variable "x".
Error in ==> lsqcurvefit at 182
[x,Resnorm,FVAL,EXITFLAG,OUTPUT,LAMBDA,JACOB] = ...
Error in ==> lassafitw at 75
[x,Rsdnrm] = lsqcurvefit(@Model_Inc,x0,xdata,ydata,LB,UB,optimset);
function lassafitw(do_estimation)
warning off;
P_Data(:,1)=[1:80];
P_Data(:,2)=[ 0 16 117 252 305 386 454 525 574 646 717 783 848 910 1026 1261 1361 1424 1620 1673 1813 1940 2021 2304 2437 2950 3252 3410 3706 ...
3896 5235 5338 4759 4862 5368 5586 6073 6190 6599 7109 7312 7897 8356 9004 9446 9780 10124 10934 11103 11466 11751 11841 11974 12022 12244 ...
12313 12440 12593 127666 12735 12827 12884 12962 13012 13093 13150 13241 13402 13518 13586 13638 13701 13785 13894 13928 13945 13992 ...
14001 14052 14122]./3800;
piH = 20;
muH = 0.02;
d1=0.2;
piR=5;
eR=0.01;
rhoR=0.01;
muR=0.02;
d2=0.15;
rho3=0.05;
rho6=0.6;
rho2=0.6;
rho1=0.02;
rho7=0.2;
rho5=0.03;
omega=0.6;
rho4=0.5;
gamma=0.03;
beta1=0.2;
beta2=0.1;
beta3=0.08;
beta4=0.2;
beta5=0.02;
Sh0=100000; Eh0=2000; Eth0=0; Enh0=0; Ih0=0; Iqh0=0;Dh0=0; Sr0=500;Er0=0;Ir0=0;
INITIAL=[Sh0, Eh0, Eth0, Enh0, Ih0,Iqh0,Dh0, Sr0,Er0,Ir0];
Istart=1; %month to start the model simulation
Iend=Istart + 81;
OPTIONS=odeset('AbsTol',0.0001,'RelTol',0.0001,'MaxStep',1/12);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Estimate parameters
%by minimizing the sum of squares
%when fitting modeled to real prevalence data
do_estimation=1;
if(do_estimation)
xdata=P_Data(:,1)';
ydata=P_Data(:,2)';
x0(1,1)= 20; %Lambda
x0(1,2)=0.02; %mu
x0(1,3)= 0.2; %beta
x0(1,4)= 5; %0.1; %sigma
x0(1,5)=0.01; %0.005; %gamma
x0(1,6)=0.01; %0.005; %p
x0(1,7)= 0.02; %0.00001; %theta
x0(1,8)= 0.15; %0.0008; %delta1
x0(1,9)= 0.05; %0.004; %delta2
x0(1,10)= 0.6; %c
x0(1,11)= 0.6; %omega
x0(1,12)= 0.02; %alpha1
x0(1,13)= 0.2; %alpha2
x0(1,14)= 0.03; %alpha3
x0(1,15)= 0.6; %alpha4
x0(1,16)= 0.5; %alpha5
x0(1,17)= 0.03;
x0(1,18)= 0.2;
x0(1,19)= 0.1;
x0(1,20)= 0.08;
x0(1,21)= 0.2;
x0(1,22)= 0.02;
LB=[10 0 0.0001 5 0.0 0.000 0.0060 0.0060 0.0060 1 0.008 0.003 0 0 0 0 0 0 0 0 0 0 ];
UB=[50 1 1.5 20 0.9 0.9 0.9 0.9 0.9 10 1 1 1 1 1 1 1 1 1 1 1 5 5 ];
[x,Rsdnrm] = lsqcurvefit(@Model_Inc,x0,xdata,ydata,LB,UB,optimset);
'estimated parameters'
piH=x(1);
muH=x(2);
d1=x(3);
piR=x(4);
eR=x(5);
rhoR=x(6);
muR=x(7);
d2=x(8);
rho3=x(9);
rho6=x(10);
rho2=x(11);
rho1=x(12);
rho7=x(13);
rho5=x(14);
omega=x(15);
rho4=x(16);
gamma=x(17);
beta1=x(18);
beta2=x(19);
beta3=x(20);
beta4=x(21);
beta5=x(22);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[t y] = ode45(@lassafitw,[0:1/12:(Iend-Istart)], INITIAL);
Sh=y(:,1);
Eh=y(:,2);
Eth=y(:,3);
Enh=y(:,4);
Ih=y(:,5);
Iqh=y(:,6);
Dh=y(:,7);
Sr=y(:,8);
Er=y(:,9);
Ir=y(:,10);
incidence= beta1*y(:,5) + beta2*y(:,6);
%incidence= y(:,4)*gamma;
close all;
figure(1);
hold on
h_l=plot(Istart+t,incidence,'r-');
set(h_l,'linewidth',2);
h_l=plot(P_Data(:,1),P_Data(:,2),'bo','Markersize',6);
set(h_l,'linewidth',2);
axis([Istart Iend 0 9]);
%ylim([0 45.00]) % The line added to change the y limit
%title('Ebola Prevalence(%)');
xlabel('Days','fontsize',15)
ylabel('Ebola Incidence','fontsize', 15)
hold off
function [ydot]=lassafitw(t,y)
Sh=y(1);
Eh=y(2);
Eth=y(3);
Enh=y(4);
Ih=y(5);
Iqh=y(6);
Dh=y(7);
Sr=y(8);
Er=y(9);
Ir=y(10);
ydot(1)=piH - beta4*y(9)*y(1)/(y(8)+y(9)+y(10)) -(beta1*y(5)+beta2*y(6)+beta3*y(7))*y(1)/(y(1)+y(2)+y(3)+y(4)+y(5)+y(6)+y(7))-muH*y(1)+rho3*y(3)+rho6*y(7);
ydot(2)=beta4*y(9)*y(1)/(y(8)+y(9)+y(10))+(beta1*y(5)+beta2*y(6)+beta3*y(7))*y(1)/(y(1)+y(2)+y(3)+y(4)+y(5)+y(6)+y(7)) -((1-omega)*rho2+ omega*rho1+muH)*y(2);
ydot(3)=(1-omega)*rho2*y(2)-(rho3+rho4+muH)*y(3);
ydot(4)=omega*rho1*y(2)-(rho5+muH)*y(4);
ydot(5)=rho5*y(4)-(rho7+d1+muH)*y(5);
ydot(6)=rho7*y(5)+rho4*y(3)-(rho6+d2+muH)*y(6);
ydot(7)=d1*y(5)+d2*y(6) - gamma*x(7);
ydot(8)=piR - beta5*y(9)*y(8)/NR - (muR+rhoR)*y(8);
ydot(9)=beta5*y(9)*y(8)/NR -(muR+rhoR+eR)*y(9);
ydot(10)=eR*y(9)-(muR+rhoR)*y(10);
ydot = ydot';
end % function
function Inc=Model_Inc(x0,xdata)
% Inc=0; %initialization of this not to have an empty array
piH=x0(1);
muH=x0(2);
d1=x0(3);
piR=x0(4);
eR=x0(5);
rhoR=x0(6);
muR=x0(7);
d2=x0(8);
rho3=x0(9);
rho6=x0(10);
rho2=x0(11);
rho1=x0(12);
rho7=x0(13);
rho5=x0(14);
omega=x0(15);
rho4=x0(16);
gamma=x0(17);
beta1=x0(18);
beta2=x0(19);
beta3=x0(20);
beta4=x0(21);
beta5=x0(22);
%%% Initial values
Sh0=100000; Eh0=2000; Eth0=0; Enh0=0; Ih0=0; Iqh0=0;Dh0=0; Sr0=500;Er0=0;Ir0=0;
INITIAL=[Sh0, Eh0, Eth0, Enh0, Ih0,Iqh0,Dh0,Sr0,Er0,Ir0];
OPTIONS=odeset('AbsTol',0.0001,'RelTol',0.0001,'MaxStep',1/12);
tdur=50;
[t y] = ode45(@lassafitw, [0:1/12:Iend-Istart], INITIAL);
Sh=y(:,1);
Eh=y(:,2);
Eth=y(:,3);
Enh=y(:,4);
Ih=y(:,5);
Iqh=y(:,6);
Dh=y(:,7);
Sr=y(:,8);
Er=y(:,9);
Ir=y(:,10);
incidence= beta1*y(:,5) + beta2*y(:,6)
%incidence= y(:,4)*gamma;
for i=1:length(xdata)
ind=find(xdata(i)-Istart==t);
Sh=y(ind,1);
Eh=y(ind,2);
Eth=y(ind,3);
Enh=y(ind,4);
Ih=y(ind,5);
Iqh=y(ind,6);
Dh=y(ind,7);
Sr=y(ind,8);
Er=y(ind,9);
Ir=y(ind,10);
Inc(i)= beta1*Ih + beta2*Iqh; %incidence
%Inc(i)= Is*gamma; %incidence
end
end % end of Model_prev
Q1= gamma + mu;
Q2= mu + theta + delta1;
Q3 = delta2 + sigma + mu;
mstar= Lambda*gamma1 / omega* mu;
R_M = beta*c*gamma*(rho + eta*sigma)*(1-mstar)*(p*theta + Q2*(1-p))/(rho*Q1*Q2*Q3)
end %end of ebola_fitChinwendu Madubuezehttps://it.mathworks.com/matlabcentral/profile/authors/16821769-chinwendu-madubuezetag:it.mathworks.com,2005:Question/5409172020-06-02T21:45:34Z2020-06-02T21:45:34ZMex compiler compatibility on Mac OS CatalinaI keep getting the following error: Error using mex
No supported compiler was found. For options, visit https://www.mathworks.com/support/compilers.
I have installed the latest XCode (and moved it to 'Applications') as well as mingw64 for Mac. It's still not finding the compiler. I am using MATLAB R2020a.
Any help will truly be appreciated. Thanks in advance.
Melanie Rennhttps://it.mathworks.com/matlabcentral/profile/authors/18261876-melanie-renntag:it.mathworks.com,2005:Question/5408842020-06-02T20:52:44Z2020-06-02T21:45:14Zfprint problem in matlab why the outstr value is 24 here ?
Mariahttps://it.mathworks.com/matlabcentral/profile/authors/18485433-mariatag:it.mathworks.com,2005:Question/5409142020-06-02T21:40:23Z2020-06-02T21:42:44ZError while using Size . Hello everyone ,
I am really bemused.
Size is not working anymore and keeps sending an error message even for basic algorithms !
For instance :
A = rand(2,3,4,5);
sz = size(A)
Array indices must be positive integers or logical values.
Error in Untitled4 (line 2)
sz = size(A)
Or even
A= [1 2 3]
sz= size(A)
Index exceeds the number of array elements (2).
Error in Untitled4 (line 2)
sz= size(A)
Help plz .
Thx in advancejad aounhttps://it.mathworks.com/matlabcentral/profile/authors/17059965-jad-aountag:it.mathworks.com,2005:Question/5408932020-06-02T21:09:45Z2020-06-02T21:41:39ZVector as input for plotting functionHello,
i would like to plot with red stars the function: sinc(x)= [sin(πx)]/[πx]
but x would be a vector given by the user
I really dont know how to ask the user to give me the vector and how can i use it as input for my function.Eleftherios Venizeloshttps://it.mathworks.com/matlabcentral/profile/authors/18674541-eleftherios-venizelostag:it.mathworks.com,2005:Question/5409112020-06-02T21:39:47Z2020-06-02T21:40:56ZTwo-Phase fluid - Weird Temperature peakHi people,
I am trying that really nice SimScape two-phase fluid library.
I am simulating a double acting steam free piston.
It is running without errors (most of the time, depends a lot on the valve pipe diameter I set ...), but the weird thing is when I increase the reservoir volume, the temperature suddenly shows really high peak in the beginnnig of the stroke (like if it was overheated steam).
Which is pretty surprising since I would expect a rise of pressure when the piston compress the fresh steam, not temperature ?
And the peak to be lower and lower when volume increase, but it is the contrary happening.
Any idea why is it happening ? It doesn't seems right to me.
Thank !
Joris Naudinhttps://it.mathworks.com/matlabcentral/profile/authors/14918767-joris-naudintag:it.mathworks.com,2005:Question/5408572020-06-02T19:56:25Z2020-06-02T21:35:00ZIf you have an unknown function of 2 variables, and you have generated data on this function that does not necessarily fit on to a rectangular grid, how would you plot this data? (Answer either verbally or with exemplary Matlab code).If you have an unknown function of 2 variables, and you have generated data on this function that does not necessarily fit on to a rectangular grid, how would you plot this data? (Answer either verbally or with exemplary Matlab code).Ibrahim Yildizhttps://it.mathworks.com/matlabcentral/profile/authors/17480727-ibrahim-yildiztag:it.mathworks.com,2005:Question/5409052020-06-02T21:20:05Z2020-06-02T21:20:05ZHow do i import a system of differential equations from GUI to functions in a way that it can be properly solved?I'm trying to make a GUI to solve a system of linear first-order differential equations, so the code that i'm using to get the equations from the GUI is this one:
strF = get(handles.eF,'String');
strG = get(handles.eG,'String');
f=@(t,u,v) eval(vectorize(strF));
g=@(t,u,v) eval(vectorize(strG));
syms u(t) v(t)
So, in a specific case, the equation i wrote is 3*u + 4*v and -4*u + 3*v, f and g respectively. And these variables do have the equations stored in that way, but when i try to solve the system it doesn't solve it well. This is the code i used to solve it:
ode1= diff(u)==f;
ode2= diff(v)==g;
odes = [ode1; ode2];
S = dsolve(odes);
uSol(t) = S.u;
vSol(t) = S.v;
And i get this result, which is wrong.
uSol(t) = C1 + t*(3*u + 4*v)
vSol(t) = C2 - t*(4*u - 3*v)
but when i replace f and g for their value,
ode1= diff(u)==3*u + 4*v;
ode2= diff(v)==-4*u + 3*v;
it gives me the right result. So i assume it is the way that i import the equations from the GUI
Does anyone know how can i fix this?
João Silvahttps://it.mathworks.com/matlabcentral/profile/authors/18111733-joao-silvatag:it.mathworks.com,2005:Question/5394552020-06-01T06:19:06Z2020-06-02T21:18:10ZImage translation using fourier transformI have shifted an image by certain pixels in the Fourier (frequency) domain and brought it back to the time domain. My question is if the noise associated with my image before translation is same as the noise associated with it after translation.Asrith Pylahttps://it.mathworks.com/matlabcentral/profile/authors/9464323-asrith-pylatag:it.mathworks.com,2005:Question/5371352020-05-29T05:04:42Z2020-06-02T21:17:03Zexportgraphics r2020a issueI am using exportgraphics command to export hihg quality images.
exportgraphics(gcf,[filenames(1:end-4),'.tiff'], 'Resolution', 300);
Bur, exported image output as attached here. for some reason, part of the screen is saved as black. does anybody know the solution? Kinldy help.
if i use
saveas(gcf,filenames(1:end-4),'tiff');
MShttps://it.mathworks.com/matlabcentral/profile/authors/14649285-mstag:it.mathworks.com,2005:Question/5409022020-06-02T21:14:53Z2020-06-02T21:14:53ZHow to make nPr formula as the perms function makes nPn only ?How to make nPr formula as the perms function makes nPn only ?Abdelrhman Nasrhttps://it.mathworks.com/matlabcentral/profile/authors/7114036-abdelrhman-nasrtag:it.mathworks.com,2005:Question/5408962020-06-02T21:10:42Z2020-06-02T21:10:42ZApp inside app questionHello MATLAB community!
I am an undergraduate new to MATLAB, and I am trying to build an app inside MATLAB to collect/analyze data for a neuroscience research project.
Is it possible to build an app (or in my case, four apps) within a "mother" app? I tried creating one app but it was ridiculously slow to load an image. I hope linking different apps will make this process much quicker.
If this is possible, how do I go about connecting the apps? Thanks so much!Lucia Wagnerhttps://it.mathworks.com/matlabcentral/profile/authors/11832909-lucia-wagnertag:it.mathworks.com,2005:Question/5407542020-06-02T17:27:10Z2020-06-02T21:08:34ZHow can I apply a function to an image to make it find figure shapes in that image ? Hi!
I've got 3 diffirent shapes in image:
1) The red one can be described with r1 = 3-3cos(thetha) (polar coordinate system)
2) The blue one can be described with r2 = tan(sin(2*thetha)) (polar coordinate system)
3) The green one can be described with r3 = 5-4sin(2*thetha) (polar coordinate system)
So I give MatLab as in imput an image with 3 diffrent shapes, every shape can be described with it's own mathematical function (wrote about it in the begining) I've got 3 functions, and also i know how their graphs in polar coordinate look like
So now, i wanna make MatLab to work in the following way:
1) MatLab already got image with 3 different shapes as an imput;
2) I've wrote down in a live script all 3 mathematical function, that can describe my shapes in image (function's graph in polar coordinate has the same shape as the shape in image)
3) I don't understand completely how, but MatLab should do the following ( he sees a red shape in image, then he should somehow understand, that function's r1=3-3cos(thetha) graph shape is the same shape as he sees in image (the red shape in image))
4) Then he should find out that the red shape in image, can be described with r1=3-3cos(thetha) function and then he should say that red shape in image can be described with function r1=3-3cos(thetha) and tell me about this Is this possible to do as i am asking or not?
And the last thing - all these 3 shapes in image are not red/blue/green, they are grey, i've used colours in desmos just to say that there are 3 different shapes and every shape can be desctibed with it's mathematical functions ( to do that, just fo clearness, i've made them red/green/blue, so that's can't be related to a rgb image, it's just line colours in desmos)
So I’m just asking whether I can do it in deep learning toolbox, cause I’ve tried to do it in image processing toolbox and didn’t succeed, cause I know what should I do, but I completely misunderstand, even in which way should I work, like, which toolbox for example I need to choose in the beginning.
Please be patient, I’m kinda of a Matlab lamerDmitry Surovhttps://it.mathworks.com/matlabcentral/profile/authors/18065714-dmitry-surovtag:it.mathworks.com,2005:Question/5398512020-06-01T15:50:54Z2020-06-02T20:58:24Zhow can i fix indexes for the train, val and test in train function? and how can i return the testing accuracy exactly like it appears in the plot confusion matrix?Dear Friends, i'm using the code below: to classify by berlin audio dataset, my dataset is not mixed, every group of audio files related are seperated from other groups,
please i have two questions: why isnt the fixed indexing working and how can i access the testing performance that appears in the confusion matrix of the the plotconfusion, please help me, a need it urgent in my work.
close all;
clear all;
clc;
%loading the berlin dataset
load berlin.mat;
%loading the target 0,1 matrix
load binary_matrix_berlin;
%rotating the both matrices
x = rot90(cell2mat(fin));
t = binary_matrix_berlin';
[ I N ] = size(x); % [ 2 1000]
[ O N ] = size(t); % [ 4 1000]
%there are seven groups in my dataset and i'm trying to classify them from each other, the set_1 is from file no. 1 to file number 69, the set_2 is from file no. 70 to file no. 115 an so on, so using the net.divideFcn = 'dividerand' doesnt work with me, i have to use the 'divideInd', but is not working, please help me in this issue.
% Choose a Training Function
% For a list of all training functions type: help nntrain
% 'trainlm' is usually fastest.
% 'trainbr' takes longer but may be better for challenging problems.
% 'trainscg' uses less memory. Suitable in low memory situations.
trainFcn = 'trainscg'; % Scaled conjugate gradient backpropagation.
% Create a Pattern Recognition Network
hiddenLayerSize = [80 40];
net = patternnet(hiddenLayerSize, trainFcn);
% Choose Input and Output Pre/Post-Processing Functions
% For a list of all processing functions type: help nnprocess
net.input.processFcns = {'removeconstantrows','mapminmax'};
% Setup Division of Data for Training, Validation, Testing
% For a list of all data division functions type: help nndivision
net.divideFcn = 'divideInd'; % Divide data by index
net.divideParam.trainnum = [1:42,70:97,116:158,187:235,268:315,347:384,409:485];
net.divideParam.valnum = [43:49,98:102,159:166,236:244,316:323,385:391,486:498];
net.divideParam.testnum = [50:69,103:115,167:186,245:267,324:346,392:408,499:535];
% Choose a Performance Function
% For a list of all performance functions type: help nnperformance
net.performFcn = 'mse'; % Cross-Entropy
% Choose Plot Functions
% For a list of all plot functions type: help nnplot
net.plotFcns = {'plotperform','plottrainstate','ploterrhist', ...
'plotconfusion', 'plotroc'};
% Train the Network
[net,tr] = train(net,x,t);
%.........................................................
% Test the Network
y = net(x);
e = gsubtract(t,y);
performance = perform(net,t,y)
tind = vec2ind(t);
%a vector representing all the samples of the dataset predicted after
%training the NN.
yind = vec2ind(y);
%the percentage error of the all confusion matrix
percentErrors = sum(tind ~= yind)/numel(tind);
%...........................................................
% Recalculate Training, Validation and Test Performance
%in the list of functions listed below, non of them is giving me the testing performance, as it appears in the plotconfusion "test confusion matrix", please i need the function that can return the testing performance only, or its error percentage, "the testing results after applying the testing samples to the neural network only".
trainTargets = t .* tr.trainMask{1};
valTargets = t .* tr.valMask{1};
testTargets = t .* tr.testMask{1};
trainPerformance = perform(net,trainTargets,y)
valPerformance = perform(net,valTargets,y)
testPerformance = perform(net,testTargets,y)
% View the Network
view(net)Husam Alihttps://it.mathworks.com/matlabcentral/profile/authors/18450115-husam-alitag:it.mathworks.com,2005:Question/5404592020-06-02T12:09:52Z2020-06-02T20:57:12Zhow do i create a surface around two circles of different diameters located a specific position??? can anyone please help me with generation of mesh or surface around circles.... shall remain thankful. please see the code below... i want to create surface around 3 circles of different radius.... i tried using mesh and surf but not been able to do it.sohaib khanhttps://it.mathworks.com/matlabcentral/profile/authors/2885087-sohaib-khantag:it.mathworks.com,2005:Question/2546962015-11-13T17:52:20Z2020-06-02T20:56:48ZHow to assign gradual color to a 3d line based on values of another vectorHi all,
I want to assign colour to lines plotted between 3dpoints, based on the values of a fourth vector.
The values of the fourth vector are not sorted in any way, and they are both positive and negative values.
I did a for loop to plot a line between the nodes that have connectivity, and I'm assigning the color as well.
I think I'm having problems with the way I'm sorting the fourth value. But can't figure it out how to make it work.
Here is the code:
myColourMap=jet(m);
s=stresses;
[s,I]=sort(s);
for i=1:m
Intensity = I(i);
LineColour=myColourMap(Intensity,:);
plot3([ x(t1(i)) x(t2(i))], [ y(t1(i)) y(t2(i))], [ z(t1(i)) z(t2(i))],'Color', LineColour)
hold on
end
axis equal
colorbar
The four vector is the 's' vector, and when I plotted the network of lines, the colour it assign to each one, does not represent the ascending or descending of the values in vector s(which represent stresses). I appreciate very much any help of how to plot the lines based on the values of a vector, or if the problem is the sorting, then, how to obtain the ordering indices of the vector s.
Thanks a lot in advance
MarthaMarthahttps://it.mathworks.com/matlabcentral/profile/authors/4934229-marthatag:it.mathworks.com,2005:Question/5271392020-05-19T22:08:25Z2020-06-02T20:54:26ZHow do I write files in NITF format?How do I write files in NITF format? I see the readnitffunction but I don't see a writenitf function.Raymond Walterhttps://it.mathworks.com/matlabcentral/profile/authors/3259139-raymond-waltertag:it.mathworks.com,2005:Question/5407612020-06-02T17:34:52Z2020-06-02T20:53:57ZHow can I obtain my expected result?I typed this code
function out=picker(c,in1,in2)
if c
out=fprintf('%d\n'in1);
else
out=fprintf('%d\n'in2);
end
my desire was to get this reslut
>>out=picker(true,5,6)
out=5
>>out=picker(false,5,6)
out=6
but matlab found a bug here .What is wrong with my code and how can I obtain my expected result?
Sabid Hossainhttps://it.mathworks.com/matlabcentral/profile/authors/18641044-sabid-hossaintag:it.mathworks.com,2005:Question/5408632020-06-02T20:27:42Z2020-06-02T20:52:31ZUpgrade MATLAB from r2013b to r2017b problem.....I had a code prepared in MATLAB version r2013b , I upgraded my MATLAB version to r2017b and the same program that executed quite smoothly in the prevoius version now gives the follwoing error....
Error using ^
One argument must be a square matrix and the other must be a scalar. Use POWER (.^) for elementwise power.
The question is that either its just due to the change of vesion or either I was getting wrong results prevoiusly. (Previously for r2013b I rechecked all parameter values uisng Mathematica and both were same)
Kindly anyone help in this capacity.Atique Khanhttps://it.mathworks.com/matlabcentral/profile/authors/9466471-atique-khantag:it.mathworks.com,2005:Question/5408722020-06-02T20:35:20Z2020-06-02T20:50:04ZHow to read accelerometer sensor data from Surface tablet, please?Hi, I really need your help and advice, please...
I need to use MATLAB to read accelerometer sensor data from a Surface tablet (Windows 10). The sensor is built-in in the tablet, so I don’t know which port it is.
The Device Manger doesn't display any port in the list. I think this is because this accelerometer sensor is built-in, not from a USB port. I have also tried some functions in MATLAB such as ‘serialportlist’ and ‘read’, but none of them worked.
If you could give me some comments that will be very helpful. Thank you very much.Norman Shttps://it.mathworks.com/matlabcentral/profile/authors/18674330-norman-stag:it.mathworks.com,2005:Question/5166762020-04-09T16:07:51Z2020-06-02T20:45:22Zwrite a function called tri_area returns the area of a triangle with base b and height h hello this is my function code and command window code and there is a message of invalid expression at line 2 and i dont know what is the wrong can anyone help me
function [area] = tri_area([b,h]);
tri_area([b,h])=(0.5)*(b)*(h)
area=tri_area([b,h])
end
%command window
area = tri_area[3,2])Andrew Aymanhttps://it.mathworks.com/matlabcentral/profile/authors/18061673-andrew-aymantag:it.mathworks.com,2005:Question/5408002020-06-02T18:20:13Z2020-06-02T20:42:03ZHow to count the number of times I called a function (using the command line)Hi,
The backstory: So I'm trying to design an image analysis tool on App Designer where I "feed" an image through a function, do some analysis in my function, output numerical results, verfiy to see if the analysis was done correctly visually, save the function outputs into a spreadsheet, and repeat the process with a different image. The first time the function is called, the results will be stored in the first row of the array; the second time it is called it will be stored in the second row of the array so on and so forth. I figured that to do this, I need to have someway to keep track of how many times my function is called. So I'm testing this with a simpler example:
function p = myfunction(a,b,c)
counter=0; %Initializing counter
parabola
function parabola
e = a+5
f = b+10
g= c+100
store=[e,f,g] %Still figuring out how to define the row associated with the counter to store my variable
end
counter = counter+1
end
However, I'm at to how I can not make the counter reset everytime I pass a new function.
For instance, if I were to do myfunction(1,2,3) followed by myfunction(2,3,4) I would still get counter =1.
Any help for this novice will be highly appreciated!!William Panghttps://it.mathworks.com/matlabcentral/profile/authors/9967325-william-pangtag:it.mathworks.com,2005:Question/5408812020-06-02T20:41:58Z2020-06-02T20:41:58Zfopen cannot read directory names in scientific formatHi everyone, I have some data that is stored as .csv file in different directories. After looking through this forum, I have managed to find a way of extracting the relevant .csv file from the different directories, using the code provided in this post https://uk.mathworks.com/matlabcentral/answers/278950-i-m-trying-to-write-a-code-that-import-several-data-from-multiple-folder.
The code works fine until it encounters a directory name in scientific notation and it stops with the error:
Error using textscan
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in multipleDirectories_subfolders_test (line 27)
MyData{end+1} = textscan(fileID, formatSpec, 'Delimiter', ',', 'HeaderLines',startRow-1); % format depends on files % this line might need changing
The code is attached. I've also tried using csvread but I still run into problems with this. After setting a few breakpoints in the code I've identified the problem to be the format of some directories being in scientific notation as shown in the following screenshot:
The code reads perfectly fine the .csv files in the 0, 0.0001, 0.00102, 0.000104, 0.000106 directories but the file identifier becomes invalid for the remaining directories.
Does anyone know how to solve this? It looks like fopen can only deal with integer type directories so the error is not due to textscan or csvread.
I'm really at a loss as to how to import the data otherwise.
p.s. The directories are by default saved in that format from a separate software and there's hundreds of them so changing the name manually is not really an option.Jacqueline Mifsudhttps://it.mathworks.com/matlabcentral/profile/authors/12431261-jacqueline-mifsudtag:it.mathworks.com,2005:Question/5406412020-06-02T15:02:10Z2020-06-02T20:41:24Zcreate array and assign the values to proper locations I would like store each value and add them to the previous to create an array ...
expected result should be= [-8 0 0 0 0 0 0 8], however my output is [-8 0 0 0 0 0 0 0] seems the values does NOT store and change everytime ??
clear all; clc;
t=16;
t_all=[8 0 0 0 0 0 0 8];
for i=1:8
z_all=-t/2; % I want have this number as the first element in the new array
z_all(i)=z_all+t_all(i)
end
z_all(1)=-t/2; z_all(2)=z_all(1)+t_all(1); z_all(3)=z_all(2)+t_all(2); z_all(4)=z_all(3)+t_all(3) and so on.. until
z_all(9)=z_all(8)+t_all(8)....
Hope anyone can help!!Ali Tawfikhttps://it.mathworks.com/matlabcentral/profile/authors/13520758-ali-tawfiktag:it.mathworks.com,2005:Question/5408782020-06-02T20:41:12Z2020-06-02T20:41:12Zerror performance of ASK demodulatorcan someone please tell me what is the "error performance of ASK demodulator"??
i searched alot but didn't find anything useful
thank youMohammed Falahhttps://it.mathworks.com/matlabcentral/profile/authors/18669043-mohammed-falahtag:it.mathworks.com,2005:Question/5147162020-04-01T23:53:11Z2020-06-02T20:40:50ZI cannot find the helper functions "processImagesMNIST" and "processLabelsMNIST"In the documentation linked below ("Train Variational Autoencoder (VAE) to Generate Images") the two helper functions, mentioned in the title of this question, are said to be attached in the example and they are supposed to read the MNIST files and store them in MATLAB arrays.
However, I cannot find these helper functions and I have searched everywhere without result. I used some other loading functions instead but then I encounter problems when trying to implement the images correctly, probably because of dimension problems in the input data.
Thankful if somebody can help me find the functions or similar ones which can work in the example code in the link below.
https://se.mathworks.com/help/deeplearning/ug/train-a-variational-autoencoder-vae-to-generate-images.htmlDavid Olofssonhttps://it.mathworks.com/matlabcentral/profile/authors/7672617-david-olofssontag:it.mathworks.com,2005:Question/4137222018-08-06T11:33:56Z2020-06-02T20:40:40ZSelection color in uicontrol listboxHey all!
I'm wondering if there is a way to control the highlight selection color (currently blue) in a list box? See attached example.
TIA!
TrevorTrevor Harrishttps://it.mathworks.com/matlabcentral/profile/authors/7619852-trevor-harristag:it.mathworks.com,2005:Question/5408752020-06-02T20:40:00Z2020-06-02T20:40:00ZHow do I impose constraints for each time step of the calculation?Hello,
I am trying to find the optimal size for each component in a microgrid power system. The system has a battery with a state of charge SOC that I calculate as :
SOC=zeros(8760,1);
SOC(1)=SOC_min;
for t=2:8760
if Npv*P_pv_each(t)*eta_inv-P_dmd(t)>0
mu_c=1;
mu_d=0;
else
mu_c=0;
mu_d=1;
end
SOC(t)=SOC(t-1)*(1-SD)+(mu_c*(Npv*P_pv_each(t)-P_dmd(t))*eta_bat_c/eta_inv + mu_d*(Npv*P_pv_each(t)/eta_inv-P_dmd(t))*eta_bat_d);
end
The SOC needs to obey a set of constraints that I formulate as:
% Inequality constraints
PVEVopt.Constraint.const1=SOC_min<=SOC(t); % Guarantee minimum SOC
PVEVopt.Constraint.const2=SOC(t)<=SOC_max; % Do not exceed maximum SOC I.e battery capacity
PVEVopt.Constraint.const3=abs(SOC(t)-SOC(t-1)*(1-SD))*1000/V_bus<=I_max; % Limite charging/Discharging current
can I have this for loop in my program followed by the constraints like this? What would be another way to impose these constraints
ThanksHoussem Youneshttps://it.mathworks.com/matlabcentral/profile/authors/16157678-houssem-younes