https://se.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions2020-05-29T11:32:28Ztag:se.mathworks.com,2005:Question/5366512020-05-28T16:27:43Z2020-05-29T11:32:28ZA question about checking the significant difference between data setsDear All,
I have 3 columns of data (C1, C2, C3) which represents modeled precipitation values (360 rows) using three different models, I want to found if the difference between these three models is significant or not. I searched a lot and found that Matlab has a t-student test function that can do this.
Since there are ttest and ttset2 functions I want to ask you is it true to perform ttest2 between C1 and C2 and then doing this for C2 and C3, and finally for C1 and C3 ?
Does any alternative way exist in Matlab?
Any help or advice is highly appreciated.
Thanks a lotBehzad Navidihttps://se.mathworks.com/matlabcentral/profile/authors/15525777-behzad-naviditag:se.mathworks.com,2005:Question/5367592020-05-28T18:31:34Z2020-05-29T11:26:01ZHow to get the surface roughness of the top surface of a 3D matrix.Hello,
I have a 3D matrix A, let B equal
B=(size(A,1)/2,:,:);
imshow(squeezeB());
this imshow gives the image in the attachement
How to get the surface roughness of the top of the matrix A in [a.u] unit ?Hassan Zhairabanyhttps://se.mathworks.com/matlabcentral/profile/authors/18461799-hassan-zhairabanytag:se.mathworks.com,2005:Question/5334082020-05-25T21:28:22Z2020-05-29T11:25:56ZMulti Objective Multi Reservoir Optimization (NSGA II) FormulationI want to optimize a reservoir system with NSGA II (gamultiobj). I just aimed to build an imaginary reservoir system that works with random values in order to understand the system. But I have not been able to proceed for a while. I share the code below. I have 4 reservoirs for 3 time steps. I would like to maximize the total water release for energy and irrigation withdrawal (2 objective). Do I need to write symbolic math? I examined the examples, but I could not solve it. I would be glad if you can help.
%%%%% 4 RESERVOIR EXAMPLE %%%%
%
% |
% |
% v
% ÆÆÆ
% | ÆÆÆÆÆ
% | [2]
% | |
% v v
% ÆÆÆ ÆÆÆ
% ÆÆÆÆÆ ÆÆÆÆÆ
% [1] [3]
% |__ __ __ __|
% |
% |
% v
% ÆÆÆ
% ÆÆÆÆÆ
% [4]
%
% X (i,t)
% i = RESERVOIR INDEX
% t = TIMESTEP
% EN: RELEASE FOR GENERATING ENERGY, IR: ABSTRACT FOR IRRIGATION DEMAND
% 4 RESERVOIR FOR 3 TIMESTEP:
% X =[EN(1,1) EN(1,2) EN(1,3)
% EN(2,1) EN(2,2) EN(2,3)
% EN(3,1) EN(3,2) EN(3,3)
% EN(4,1) EN(4,2) EN(4,3)
% IR(1,1) IR(1,2) IR(1,3)
% IR(2,1) IR(2,2) IR(2,3)
% IR(3,1) IR(3,2) IR(3,3)
% IR(4,1) IR(4,2) IR(4,3)]
% INFLOW FROM EACH SUBBASIN INTO RESERVOIR
INF =[40 40 40 ; ...
20 20 20 ; ...
20 20 20 ; ...
10 10 10 ]
% M(J,K): RESERVOIR SYSTEM CONNECTIVITY MATRIX
% (-1) FOR ABSTRACTION, (+1) RECEIVES WATER FROM UPSTREAM RESERVOIR
% RESERVOIR(J) RECEIVES WATER FOM RESERVOIR(K)
M = [-1 0 0 0 ; ...
0 -1 0 0 ; ...
0 1 -1 0 ; ...
1 0 1 -1 ]
% N(J,K): IRRIGATION SYSTEM CONNECTIVITY MATRIX
% (-1) FOR ABSTRACTION, (+1) RECEIVES RETURN WATER FROM UPSTREAM IRRIGATION
% RESERVOIR(J) RECEIVES WATER FOM IRRIGATION(K)
N = [-1 0 0 0 ; ...
0 -1 0 0 ; ...
0 1 -1 0 ; ...
1 0 1 -1 ]
% MERGE CONNECTIVITY MATRCIES
CON_MAX = [M N]
% MERGE RELEASES FOR ENERGY AND ABSTRACTIONS
% EN = ones(4,3)
% IR = ones(4,3)
X = [EN; IR]
% RELEASE FOR ENERGY AND IRRIGATION TOTAL MUST BE > 10 CMS
% A*x <= b
% -EN-IR <= -10
A = [-1 0 0 0 -1 0 0 0; ...
0 -1 0 0 0 -1 0 0; ...
0 0 -1 0 0 0 -1 0; ...
0 0 0 -1 0 0 0 -1]
b = [-10 -10 -10 ; ...
-10 -10 -10 ; ...
-10 -10 -10 ; ...
-10 -10 -10 ]
% lb < x < ub
% 0 (FOR BOTH SECTOR) < x < 100 FOR ENERGY AND 95 FOR IRRIGATION
lb = [0 0 0 ; ...
0 0 0 ; ...
0 0 0 ; ...
0 0 0 ; ...
0 0 0 ; ...
0 0 0 ; ...
0 0 0 ; ...
0 0 0 ]
ub = [100 100 100 ; ...
100 100 100 ; ...
100 100 100 ; ...
100 100 100 ; ...
95 95 95 ; ...
95 95 95 ; ...
95 95 95 ; ...
95 95 95 ]
t = 1 % START FROM TIMESTEP 1
T = 3 % TIME HORIZON (t_END)
RES_COUNT = 4 % RESERVOIR COUNT
EN_COUNT = 4 % ENERGY RELEASE COUNT
IR_COUNT = 4 % IRRIGATION ABSTRACT COUNT
NVAR = (EN_COUNT+IR_COUNT)*T %TOTAL NUMBER OF DECISION VARIABLE
% INITIAL STORAGE VOLUMES
S_0 = [10 ; ...
10 ; ...
10 ; ...
10 ]
%% CONTINUITY CONSTRAINTS
% STORAGE(t+1) = STORAGE(t) + INFLOW(t) + M*ENERGY(t) + N*IRRIGATION(t)
% STO = S0 + INF + M*EN + N*IR
% STO = S0 + INF + CON_MAX * X
STO = zeros(RES_COUNT,T);
t = 1 % ONLY FOR TIMESTEP = 1
for i = 1:4 % EACH RESERVOIR
STO(i,t) = S_0(i,t) + INF(i,t) + CON_MAX(i,t) * X(i,t) ;
end
% LOOP
for t = 2:3 % EACH TIMESTEP
for i = 1:4 % EACH RESERVOIR
STO(i,t) = STO(i,(t-1)) + INF(i,t) + CON_MAX(i,t) * X(i,t) ;
% PENALTY FUNCTIONS:
% TO OVERCOME THE GA LIMITATIONS ON HANDLING THE HIGHLY CONSTRAINED SYSTEM, THE NONLINEAR CONSTRAINTS
% ARE SATISFIED IN DIFFERENT WAYS TO TRANSFORM THE CONSTRAINED OPTIMIZATION INTO THE UNCONSTRAINED ONE.
% THE COMPUTATION OF RESERVOIR STORAGE IS BASED ON THE CONTINUITY EQUATION SO IT IS SATISFIED.
% STORAGE AND END-STORAGE CONSTRAINTS ARE INCLUDED INTO THE OBJECTIVE FUNCTION IN FORM OF PENALTY FUNCTIONS.
% THE DEVIATION FROM THE MIN AND MAX STORAGE AND END-STORAGE ARE PENALIZED BY SQUARE DIFFERENCES FROM CONSTRAINTS.
% PENALTY 1, 3 AND 3
P_1 = zeros(4,3)
P_2 = zeros(4,3)
P_3 = zeros(4,3)
% MIN AND MAX STORAGE FOR EACH RESERVOIR EACH TIMESTEP
S_MIN=[ 1 1 1 ; ...
1 1 1 ; ...
1 1 1 ; ...
1 1 1 ]
S_MAX=[ 50 50 50 ; ...
50 50 50 ; ...
50 50 50 ; ...
50 50 50 ]
% PENALTY WEIGHTED FACTOR ASSUMPTION
K_1=60
K_2=40
K_3=40
P_1 (i,t)= K_1*(S_MIN(i,t)-STO(i,t)).^2
P_2 (i,t)= K_2*(STO(i,t)-S_MAX(i,t)).^2
P_3 (i,t)= K_3*(STO(i,T)-STO(i,1)).^2
% P_1, P_2 AND P_3 WILL INSERT TO OBJECTIVE FUNCTIONS
end
end
%% SYMBOLIC MATH ??
XX = sym('x',[RES_COUNT*2,T]); % WATER RELEASE AND IRRIGATION
FF = sym('F',[RES_COUNT,T]); % FLOW INTO RESERVOIR
SS00 = sym('S0',[RES_COUNT,T]); % INITIAL STORAGE
CC = sym({'c1','c2','c3','c4'}.','real'); % CONSTANT
for t = 1:T
TOTFLOW(1:RES_COUNT,t) = M*XX(1:RES_COUNT,t) + N*XX(RES_COUNT+1:end,t);
end
t = 1
SS = cell(RES_COUNT,T);
for i = 1:RES_COUNT
SS{i,t} = SS00(i,t) + CC(1)*(FF(i,t)-TOTFLOW(i,t));
end
for t = 2:T
for ii = 1:RES_COUNT
SS{ii,t} = SS{ii,t-1} + CC(1)*(FF(ii,t)-TOTFLOW(ii,t));
end
end
%celldisp(SS)
% TOTAL EN AND IR (MINUS FOR MAX TO MIN)
for t = 1:T
for i = 1:RES_COUNT
OBJ1T(i,t) = XX(i,t);
OBJ1 = -sum(OBJ1T);
OBJ2T(i,t) = XX(RES_COUNT+i,t);
OBJ2 = -sum(OBJ2T);
end
end
% GENERATE A MATLAB FILE
matlabFunction(OBJ1,'vars',{XX},'file','OBJI1');
matlabFunction(OBJ2,'vars',{XX},'file','OBJI2');
%%
% HOW CAN I SETUP THIS FUNCTION?
% TWO OBJECTIVE FUNCTION, FOR EACH TIMESTEP:
% 1) MAXIMIZE TOTAL RELEASE FOR ENERGY
% 2) MAXIMIZE TOTAL ABSTRACTION FOR IRRIGATION
%
% fitnessfcn = @(EN,IR)[OBJ_1, OBJ_2]
%
% OBJ_1 =sum(NN*EN - (P_1 + P_2 + P_3) )
% OBJ_2 =sum(N*IR - (P_1 + P_2 + P_3) )
%
% [x,fval] = gamultiobj(@OBJ1,1,[],[],[],[],lb,ub,options)?
maxhttps://se.mathworks.com/matlabcentral/profile/authors/7563408-maxtag:se.mathworks.com,2005:Question/5374072020-05-29T11:23:12Z2020-05-29T11:23:12ZHow to generate an image from a shapefile with the same projection of a GeoTIFF?Hi,
I'm looking for a way to generate an image with the same projection of a GeoTIFF that it is independent of the shapefile (they only share the same world area).
I found a code that can generate a binary mask with the same GeoTIFF projection:
R = geotiffinfo('r_cd_geocod.tif']);
[x,y] = pixcenters(R);
[X,Y] = meshgrid(x,y);
roi = shaperead('GUF_shape_subset_fixed_repaired_wDAMAGE.shp']);
for i = 1:length(roi)
rx = roi(i).X;
ry = roi(i).Y;
mask_temp = inpolygon(X,Y,rx,ry);
mask = mask | mask_temp;
end
obtaining that:
However, I would like to associate on every polygon the corresponding damage_idx attribute:
in order to obtain something like that:
I hope that someone can solve my problem. Thank you very much for the help.Emanuele Ferrentinohttps://se.mathworks.com/matlabcentral/profile/authors/17557814-emanuele-ferrentinotag:se.mathworks.com,2005:Question/3657082017-11-07T20:57:31Z2020-05-29T11:20:45ZRunning long simulations on Matlab OnlineHi all,
I have Monte-Carlo simulations that take hours to finish (~ 17 hours). I was using a Desktop in my university Lab for this purpose, where I can keep it ON for days. But unfortunately, now I can't access it and I can't run Matlab on my laptop for that long time. By coincidence I discovered Matlab Online, and I'm wondering now is there a way to keep my code running on it even after I log out. Also, can it run 'parfor'.
Best Regards,H Hhttps://se.mathworks.com/matlabcentral/profile/authors/7507885-h-htag:se.mathworks.com,2005:Question/5371192020-05-29T04:37:23Z2020-05-29T11:17:35ZRegarding improving efficiency of the code using fzero and int (integral) function in for loop Hi ,
I am working on data generation based on user input values using probability distribution functions. I have to repetatively solve an equation with single variable , which sometimes involves integration too. I used the 'fzero' and' int' function in the code in the 'for' loop. I am facing 2 problems here:
The fzero function gets stuck in a loop , as it cannot find a real and finite solution
In case , even if it finds a solution , the program takes long time to generate the data.
I have attached the code for your reference. Run the 'f_example.m' file to check the code.Yasho Bharat Boggarapuhttps://se.mathworks.com/matlabcentral/profile/authors/11635376-yasho-bharat-boggaraputag:se.mathworks.com,2005:Question/4308282018-11-19T18:17:10Z2020-05-29T11:17:07ZWhat is the error "Value must be a double scalar" in Matlab appdesigner? Error using matlab.ui.control.internal.model.AbstractNumericComponent/set.Value (line 111) 'Value' must be a double scalar.While using app designer I wanted to save the data which the user inputs to an array. I do some calculations from them and when showing the result in the output feilds of the app, it gives me an error like this.
Error using matlab.ui.control.internal.model.AbstractNumericComponent/set.Value (line 111)
'Value' must be a double scalar.
I have attached the screen shots and below is the code. I created a function called `check`. It´s purpose is to tell the user to enter values in the blank feilds if they are empty.
I call the above function when the "result" button of the GUI is pressed. So I call ´check´ function inside the `buttonPush` function.
I use `twodecision1` and ´twodecison2´ variables as outputs. Values this two variables are assigned later written back to the GUI feilds as a display to user. Here´s the part I get error. It seems I try to assign wrong data type. Thank you in advance.
properties (Access = private)
two = [1 2; 3 4; 5 6; 7 8] ; %to store input data from GUI
twodecison1 ; %output variable
twodecision2; %output variable
end
methods (Access = private)
function results = check(app)
results = app.twodecison1;
results = app.twodecison2;
if(app.two(1,1)==0 && app.two(1,2)==0 && app.two(2,1)==0 && app.two(2,2)==0 && app.two(3,1)==0 && app.two(3,2)==0 && app.two(4,1)==0 && app.two(4,2)==0 )
app.twodecison1 =0;
app.twodecison2=0;
app.outputmessageEditField="Fill the requires feilds";
end
end
end
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
end
% Button pushed function: resultsButton
function buttonPush(app, event)
app.two(1,1) = app.StrokelengthEditField.Value;
app.two(1,2)= app.strokelengthEditField.Value;
app.two(2,1)=app.pitchEditField.Value;
app.two(2,2)=app.pitchEditField_2.Value;
app.two(3,1)=app.buildingdimensionEditField.Value;
app.two(3,2)=app.buildingdimensionEditField_2.Value;
app.two(4,1)=app.preconfignumEditField.Value;
app.two(4,2)=app.preconfignumEditField_2.Value;
app.actuator1refnoEditField.Value= app.twodecison1 ;
app.actuator2refnoEditField.Value= app.twodecison2 ;
app.check();
end
end
Ishani Mahanamahttps://se.mathworks.com/matlabcentral/profile/authors/10866649-ishani-mahanamatag:se.mathworks.com,2005:Question/5373832020-05-29T10:48:07Z2020-05-29T11:16:42ZDraw a 3D tetrahedronHi
I'm new to Matlab.
how do I draw a tetrahedron?
The 4 corner points are given.
p1(0 0 0)
p2(0 1 1)
p3(1 0 1)
p4(1 1 0)
can anyone help?Alexander Stadelhttps://se.mathworks.com/matlabcentral/profile/authors/18232137-alexander-stadeltag:se.mathworks.com,2005:Question/5373272020-05-29T10:03:10Z2020-05-29T11:16:01ZApproximate a log curve as linear to predict a valueHello there,
I have the following code:
clf
P = [0.01; 0.1; 1; 3; 5; 10; 25; 50; 75; 90; 95; 97; 99; 99.9];
phi_1 = [5.28; 4.10; 2.82; 2.15; 1.82; 1.33; 0.59; -0.12; -0.72; -1.18; -1.42; -1.57; -1.81; -2.14];
Cs_1 = Cv_Q
K_p_1 = Cv_Q.*phi_1 + ones(length(phi_1),1);
Q_p_1 = meanQ*K_p_1;
semilogx(P, Q_p_1)
Which produces this curve
My plan is to approximate a line from P = 0.01 and P = 0.1 and then plot this line to predict the Q_p value at P = 0.01.
What is the best way to go about this?
Thanks,
BrianBrian Robinsonhttps://se.mathworks.com/matlabcentral/profile/authors/15919709-brian-robinsontag:se.mathworks.com,2005:Question/4815372019-09-22T08:52:52Z2020-05-29T11:15:45ZsubmitWithConfiguration not working in matlab R2019bBeforehand on previous versions of matlab my following code was working fine. However, after upgrading to latlab R2019b, i get the following error in the submitWithConfiguration function in which it says that 'parts function is not defined.
Here is my code
function submit()
addpath('./lib');
conf.assignmentSlug = 'logistic-regression';
conf.itemName = 'Logistic Regression';
conf.partArrays = { ...
{ ...
'1', ...
{ 'sigmoid.m' }, ...
'Sigmoid Function', ...
}, ...
{ ...
'2', ...
{ 'costFunction.m' }, ...
'Logistic Regression Cost', ...
}, ...
{ ...
'3', ...
{ 'costFunction.m' }, ...
'Logistic Regression Gradient', ...
}, ...
{ ...
'4', ...
{ 'predict.m' }, ...
'Predict', ...
}, ...
{ ...
'5', ...
{ 'costFunctionReg.m' }, ...
'Regularized Logistic Regression Cost', ...
}, ...
{ ...
'6', ...
{ 'costFunctionReg.m' }, ...
'Regularized Logistic Regression Gradient', ...
}, ...
};
conf.output = @output;
submitWithConfiguration(conf);
end
function out = output(partId, auxstring)
% Random Test Cases
X = [ones(20,1) (exp(1) * sin(1:1:20))' (exp(0.5) * cos(1:1:20))'];
y = sin(X(:,1) + X(:,2)) > 0;
if partId == '1'
out = sprintf('%0.5f ', sigmoid(X));
elseif partId == '2'
out = sprintf('%0.5f ', costFunction([0.25 0.5 -0.5]', X, y));
elseif partId == '3'
[cost, grad] = costFunction([0.25 0.5 -0.5]', X, y);
out = sprintf('%0.5f ', grad);
elseif partId == '4'
out = sprintf('%0.5f ', predict([0.25 0.5 -0.5]', X));
elseif partId == '5'
out = sprintf('%0.5f ', costFunctionReg([0.25 0.5 -0.5]', X, y, 0.1));
elseif partId == '6'
[cost, grad] = costFunctionReg([0.25 0.5 -0.5]', X, y, 0.1);
out = sprintf('%0.5f ', grad);
end
end
Following is the error i get
Unrecognized function or variable 'parts'.
Error in submitWithConfiguration (line 4)
parts = parts(conf);
Error in submit (line 40)
submitWithConfiguration(conf);
Please give me some suggestions as for how to solve this. Thanks for your time!Umang Patelhttps://se.mathworks.com/matlabcentral/profile/authors/13269807-umang-pateltag:se.mathworks.com,2005:Question/5373152020-05-29T09:49:19Z2020-05-29T11:15:36ZGolden Section Search algorithm, golden number why is 0.381Hi guys, i don't understand why in tha code bellow (which works just fine) i don't understand why tau (the golden number) is 0.381.. ? I mean everywhere i look the golden number is 1.618 and if i change the constant value from 0.381 in 1.618 the code doesn't find the minimum of the function anymore. Any help is welcome. Kind regards
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% MATLAB code golden.m
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% a -> lower bound of the design variable
% b -> upper bound of the design variable
% alpha -> midpoint of a and b
% falpha1 -> function value at x = alpha1
% falpha2 -> function value at x = alpha2
% epsilon -> constant used to terminate the algorithm
% abs -> absolute of a number, MATLAB function
% tau -> 2-golden number
%
clear all
clc
a = 40;
b = 90;
epsilon = 0.00001;
tau = 0.381967;
alpha1 = a*(1-tau) + b*tau;
alpha2 = a*tau + b*(1-tau);
falpha1 = func(alpha1);
falpha2 = func(alpha2);
fprintf(' a b \n')
fprintf('-------------------------\n')
for i = 1:100
fprintf(' %7.3f %8.3f \n',a,b)
if falpha1 > falpha2
a = alpha1;
alpha1 = alpha2;
falpha1 = falpha2;
alpha2 = tau*a + (1-tau)*b;
falpha2 = func(alpha2);
else
b = alpha2;
alpha2 = alpha1;
falpha2 = falpha1;
alpha1 = tau*b + (1-tau)*a;
falpha1 = func(alpha1);
end
if abs(func(alpha1)-func(alpha2)) < epsilon
break;
end
end
fprintf('-------------------------\n')
fprintf('x* = %7.3f Minimum = %8.3f\n',alpha1,func(alpha1))
fprintf('Number of function calls = %3d\n',2+i)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% MATLAB code func.m
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% objective function to be coded here
% different test functions
%
function fx = func(x)
fx = 204165.5/(330-2*x) + 10400/(x-20);
% fx = 3*x^4+(x-1)^2;
% fx = -4*x*sin(x);
% fx = 2*(x-3)^2+exp(0.5*x*x);
%fx = 3*(x)^2+12/(x^3)-5;
% fx = 2*x*x+16/x;
%
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Emil Bucurhttps://se.mathworks.com/matlabcentral/profile/authors/18637187-emil-bucurtag:se.mathworks.com,2005:Question/5368392020-05-28T19:56:40Z2020-05-29T11:15:05ZError using vertcat. Dimensions of arrays being concatenated are not consistent.Hello,
I hope you are doing well.
I am working on a school project and I have an error that I unfortunately can't manage to understand. I am doing a mathematical modeling project where we have to use Newton's method on equations systems (in case this helps).
Here is what my console displays:
Error using vertcat
Dimensions of arrays being concatenated are not consistent.
Error in projet>@(x,y)[4*x^3,+12*y-8*x*(y^4);exp(-x^3+(y^2)/(x^2))-exp(5)] (line 51)
system2 = @(x,y)[4*x^3 +12*y - 8*x*(y^4); exp(-x^3 + (y^2)/(x^2)) - exp(5)];
Error in projet (line 56)
solution = solution(x,y)-(jacobian_system2_inverse(x,y))*(system2(x,y));
What confuses me is that the first half of the project works just fine. The Newton method seems well applied as the results given back are good.
But then, the second half, which is exactly the same thing but with different equations in it, suddenly returns an error.
You can find my whole work in the linked document.
Thank you in advance for your help,
ChloéChloé Stéphanhttps://se.mathworks.com/matlabcentral/profile/authors/17826044-chloe-stephantag:se.mathworks.com,2005:Question/5365152020-05-28T13:24:50Z2020-05-29T11:12:32Z"Scattered Interpolant" produces invalid valuesHi there, i am trying to interpolate the attached file and in some cases it the "scatteredinterpolant" produces invalid values.
Here is my code:
Tb1 = importdata('EngineModelMap.csv',';');
Tb = Tb1.data;
Tb = sortrows(Tb,[1 2]);
TET = Tb(:,3);
TH = Tb(:,4);
SFC = Tb(:,5);
ALT = Tb(:,1);
MACH = Tb(:,2);
f_TET = scatteredInterpolant(ALT,MACH,TH,TET,'natural','none');
f_sfc = scatteredInterpolant(ALT,MACH,TET,SFC,'natural','none');
f_Thrust = scatteredInterpolant(ALT,MACH,TET,TH,'natural','none');
Alt = 7000;
M = 0.6;
Tr = 13.21;
tet = f_TET(Alt,M,Tr);
sfc = f_sfc(Alt,M,tet);
ff = Tr*sfc;
% SEP,fs (max Thrust)
tetM = 1500; %max(TET);
sfcM = f_sfc(Alt,M,tetM);
Tmax = f_Thrust(Alt,M,tetM);
The issue i encounter is that some combinations that should be outside the engine map, are treated as they are inside it. For example if you set as initial values Alt=7000,M=0.6,Tr=13.21 and take a look at the imported file you will notice that Tr is out of range and thus when the tet=f_TET(Alt,M,T) is calculated should return tet=NaN. In this case though, the interpolation returns tet=1500, which is the maximum value for tet. A way to validate this miscalculation is that later on when Tmax is calculated and tet is set to 1500 (maximum tet for max thrust) the returning Tmax is ~10.
It seems like it is extrapolating, although i have disabled extrapolation.
How can i fix this issue?Laz-oshttps://se.mathworks.com/matlabcentral/profile/authors/18333728-laz-ostag:se.mathworks.com,2005:Question/5351782020-05-27T09:17:38Z2020-05-29T11:09:52Zfor loop not workingI have 2 frames of a video containing 700 balls.
I want to create a series of subimages, defined by the coordinates of the balls, so I have 700 individual ball images.
The code below generates 1 ball image, but I cannot get it to loop through the rest of the 699 ball coordinates.
Can anybody help me adapt this loop?
r = 20; %radius of whole ball
for k = 1:numFrames
%subimage the balls in frames 1 and 2 by shrinking them to the coordinates of the balls
%should produce a series of images (700 ish) showing each individual
%ball
subframe1 = frame_1(round(yb_1{k})-r:round(yb_1{k})+r, round(xb_1{k})-r:round(xb_1{k})+r); %Issue - not getting all balls
%check its worked
figure(4)
imshow(subframe1)
end C.G.https://se.mathworks.com/matlabcentral/profile/authors/13980402-c-gtag:se.mathworks.com,2005:Question/5345782020-05-26T19:51:30Z2020-05-29T11:09:04ZCan matlab save a structure to an excel file so that each individual field is saved to one excel sheet?Lets assume I have structure "struct" with fields: A, B, C and each field is a matlab table. I want to save this structure in one excel file so that each field is saved in one excel sheet like strucut.A is saved to sheet one, struct.B to sheet two and so on with the name of excel sheet being the name of that table. Becaue the number of fields are changing, I do NOT want to do this separately. I am seeking a way to do it all in once (to add the name of struct and matlab does the job).Zeynab Mousavikhamenehttps://se.mathworks.com/matlabcentral/profile/authors/14179884-zeynab-mousavikhamenetag:se.mathworks.com,2005:Question/5374032020-05-29T11:08:37Z2020-05-29T11:08:37ZSyntax: var<1d-4In the body of a program I'm using as reference, this if statement is provided:
dp=max(max(abs(phi1a-phi1)));
if(~(dp>0) & ~(dp<0) ) disp('NaN'); return; end
if(dp<1d-4) break; end % THIS LINE
where variable 'dp' is defined as so, and phi1a and ph1 are NxN matrices. What I don't understand is the second if condition - does this mean 10^-4? If so why is 'd' used, instead of 'e' as is usually.Pranav Krishnanhttps://se.mathworks.com/matlabcentral/profile/authors/17897042-pranav-krishnantag:se.mathworks.com,2005:Question/5373992020-05-29T11:07:55Z2020-05-29T11:07:55ZRegression analysis in Matlab1.
Generate a response vector corresponding to the type of function
2.Introduce noise with normal distribution law into the generated response vector
3.Find the regression equation from the obtained experimental results
4.Check the adequacy of the found regression equationArsey Shoodhttps://se.mathworks.com/matlabcentral/profile/authors/18637728-arsey-shoodtag:se.mathworks.com,2005:Question/3939682018-04-10T17:36:20Z2020-05-29T11:03:28ZFast 3d image erosion imerode for 3D image erosion takes a long time for a large 3D image data set. Is there any way to expedite the process? gpuarry does not seem to support 3d morphological operations. f1223https://se.mathworks.com/matlabcentral/profile/authors/8221518-f1223tag:se.mathworks.com,2005:Question/5373952020-05-29T10:57:36Z2020-05-29T10:57:36Zonly accept odd numbered input arguments I am writing a function and I would like it to only run if the input argument is odd, is there an easy to specifcy that the input must be odd.Ahmed Abdullahttps://se.mathworks.com/matlabcentral/profile/authors/15651567-ahmed-abdullatag:se.mathworks.com,2005:Question/5373912020-05-29T10:56:34Z2020-05-29T10:56:52Zusing a loop within a loop in matlabDear all,
I have this problem
T=1000
for ii=1:T
for t=ii:T
'here a have a function that depends on t'
end
end
If I try to run this code I get an error that 'ii' is not recognised within the second loop. Is there a way to avoid this?
Bestektorhttps://se.mathworks.com/matlabcentral/profile/authors/3484870-ektortag:se.mathworks.com,2005:Question/5368752020-05-28T20:27:59Z2020-05-29T10:55:02ZCan you help me ? Indexing errorY_beta=Yv;
N_beta=Nv;
Delta_r = [s-Y_beta / u0, 1-Yr / u0; -1*N_beta, s- Nr];
D_beta = [YdeltaR/u0, 1- Yr/u0; NdeltaR, s- Nr];
dr_appro=vpa(det(D_beta) ./ det(Delta_r) , 3);
disp('Beta transfer function:')
disp(dr_appro)
%ROLL DYNAMICS
RDra=vpa(LdeltaA ./ (s .*(s-Lp)) ,3);
disp('Roll angle transfer function:')
disp(RDra)
This is the error I obtained:
Error using sym/subsindex (line 853)
Invalid indexing or function definition. Indexing must follow MATLAB indexing. Function arguments must be symbolic variables, and function body must be sym expression.
Error in sym/subsref (line 898)
R_tilde = builtin('subsref',L_tilde,Idx);
Error in Nicolas_Moujon_new (line 192)
dr_appro=vpa(det(D_beta) ./ det(Delta_r) , 3);
I don't know how to solve it ! I just have seen that it happens few times ago. I tried by myself but unsuccessfully.
Thank you very much in advance for your help !!
Nicolas
Nicolas MOUJONhttps://se.mathworks.com/matlabcentral/profile/authors/18268650-nicolas-moujontag:se.mathworks.com,2005:Question/5373872020-05-29T10:52:47Z2020-05-29T10:52:47Zclassifing output inot categoryI have a table that contains score of mental health staus per indvidual
I would like to create vector to store the each indvidual status whether it is good or bad.
I have create the following condition
score=sdq;
count=0;
for k=1:length(score)
if score(k)>17;
count=count+1;
end
end
it works well , however, Im looking to store the new out put in a new coloumns showing the condition of good or bad mental health statusDoaa Alamoudihttps://se.mathworks.com/matlabcentral/profile/authors/16982907-doaa-alamouditag:se.mathworks.com,2005:Question/5368512020-05-28T20:05:22Z2020-05-29T10:51:36Z3D Array RasteringI am attempting to raster scan DMD mirrors by inputing a 3D array. I would like the array (for n = 2) to look like: [[1,0;0,0],[0,1;0,0],[0,0;1,0],[0,0;0,1]]. I intend to scale this array and my initial attempt hasn't been succesful. How do I create this array?
N = 4;
Array3D = zeros(2,2,N);
for row=1:2
for col=1:2
for k=1:N
Array3D(row,col,k) = 1;
end
end
end
Dillon Kopeckyhttps://se.mathworks.com/matlabcentral/profile/authors/16007178-dillon-kopeckytag:se.mathworks.com,2005:Question/5373792020-05-29T10:46:00Z2020-05-29T10:46:00ZMemory error when code ran fine beforeI'm running a code (using R2016a, Windows 10) which requires several large matrices to exist simultaneously (4 3744×256×159 matrices). I've cleared as much of the unrequired variables as possible. What is unusual is that I ran this code overnight for about 10 loops a few days ago and it worked fine. Now when I run it it won't go past the first iteration without giving an out of memory error. I have closed matlab, restarted the computer and restarted matlab in between but have not added anything to the computer or opened any other programmes which would take up RAM compared to the previous successful run. This would suggest that matlab is holding on to some data from the previous run but I don't know how to overcome this.
Any advice would be much appreciatedRoisin McMhttps://se.mathworks.com/matlabcentral/profile/authors/8634855-roisin-mcmtag:se.mathworks.com,2005:Question/5373752020-05-29T10:45:46Z2020-05-29T10:45:46ZI would like to know how to use asbQuadcopter's Open Trajectory Tool.As shown in the title above, I would like to use asbQuadcopter's Open Trail Tool.
I wanted to apply the contents of the homepage (https://kr.mathworks.com/help/aeroblks/quadcopter-project.html) at the last minute and use it.
But the drone didn't move like the last picture on the homepage.
I wonder if there is a different way to move and if there is a reference.
I think asbQuadcopter's data is too insufficient on the Internet.
Please let me know.Oseong Kwonhttps://se.mathworks.com/matlabcentral/profile/authors/15992381-oseong-kwontag:se.mathworks.com,2005:Question/5373712020-05-29T10:43:43Z2020-05-29T10:43:43ZWhat actually happens in the background during autocode generation of a Simulink model.?I need to know what actually happens during autocode generation of a Simulink model. The process involved in background.virendra patiilhttps://se.mathworks.com/matlabcentral/profile/authors/7183476-virendra-patiiltag:se.mathworks.com,2005:Question/5373472020-05-29T10:23:20Z2020-05-29T10:41:25ZPlot different length vectors on the same x-axisHi, I've got the following situation on my hands:
I have three matrixes that contain the number of epochs plus a few metrics for the training of a machine learning algorithm, for a total of 5 columns each.
The first table has 193 rows, the second and third ones have 173.
I would like to plot the second column of each matrix on the same plot, using the first column of the biggest matrix as x axis. My idea would be to obtain a plot in which the first line arrives to the limit of the x axis and the other two stop earlier.
Thank you for your attention.Mattia Boldrinihttps://se.mathworks.com/matlabcentral/profile/authors/18629533-mattia-boldrinitag:se.mathworks.com,2005:Question/5373672020-05-29T10:40:04Z2020-05-29T10:40:04ZHow do I adjust the height of the asbQuadcopter?As the title says, I would like to know how to adjust the height of the asbQuadcopter.
First, I adjusted Position/Attitude Reference to Command->Signal Editor to change the coordinates of x,y to see the drone move.
But when I changed the value of z (ex. -2,-2.5), the drone shook and the error stopped.
If you change the number to -1.5 or less, it stays still, but if you try to raise it by -2, the above situation occurs.
I wonder if there's anything I'm missing.
Is there a solution?Oseong Kwonhttps://se.mathworks.com/matlabcentral/profile/authors/15992381-oseong-kwontag:se.mathworks.com,2005:Question/5373512020-05-29T10:23:22Z2020-05-29T10:36:49Zdraw a spheres in matlab with excel dataHi
I,m very new in Matlab. I have a code to plot with Centers,Connections and Property and I want to add functions to it that read my data from excel file and draw a sphere, but it just print the data in command window and draq a figure without sphere ,Could u please help me?
(data1,2,3 are cordinates X,Y,Z and data4=raduis)
figure;
if numel(Property)==size(Centers,1)
Pval=Property; Tval=(Pval(Connections(:,1))+Pval(Connections(:,2)))./2;
end
if numel(Property)==size(Connections,1)
Tval=Property;
for I=1:numel(NW.R)
Pval(I,1)=mean(Tval(unique([find(Connections(:,1)==I) ; find(Connections(:,2)==I)])));
end
end
Tval=uint8(mat2gray(Tval).*255); Pval=uint8(mat2gray(Pval).*255);
PoreColor=squeeze(ind2rgb(Pval,jet(256)));
ThroatColor=squeeze(ind2rgb(Tval,jet(256)));
hold on;
x=Connections(:,1); y=Connections(:,2); C=Centers;
axis tight; hold on; axis equal ; view(30,40); light; grid;
X(1,:)=C(x(:),1); X(2,:)=C(y(:),1); Y(1,:)=C(x(:),2); Y(2,:)=C(y(:),2); Z(1,:)=C(x(:),3); Z(2,:)=C(y(:),3);
p =plot3(X,Y,Z,'LineWidth',2);
xlabel('X'); ylabel('Y') ; zlabel('Z');
for I=1:size(x,1)
p(I).Color=ThroatColor(I,:);
end
%scatter3(C(:,1),C(:,2),C(:,3),50,PoreColor,
%'filled','MarkerEdgeColor','k')Fatemeh%
% Centers=[ori R] % I added the radius as the fourth colum to the Centers
%matrix
[X Y Z]= sphere;
data1=xlsread('Centers.csv','M:M');
data2=xlsread('Centers.csv','N:N');
data3=xlsread('Centers.csv','O:O');
data4=xlsread('Centers.csv','AB:AB');
ori=[data1 data2 data3]
Centers=[ori data4]
for i=1:length(Centers)
s(i)=surf(X*C(i,4)+C(i,1),Y*C(i,4)+C(i,2),Z*C(i,4)+C(i,3),'EdgeColor','none');
hold on
end
%%
box on;
data=Property;
Max=max(data(:));
Min=min(data(:));
c=colorbar;
Bin=[0:.1:1];
c.Ticks=Bin;
for I=1:numel(Bin)
Labels(I)={num2str(round(Bin(I)*(Max-Min)+Min,3))};
end
c.TickLabels=Labels;
c.Label.String='Property';
colormap( jet(255));
endFatemeh Zalianisehkanehhttps://se.mathworks.com/matlabcentral/profile/authors/18493671-fatemeh-zalianisehkanehtag:se.mathworks.com,2005:Question/5373632020-05-29T10:36:21Z2020-05-29T10:36:21ZHow to check if different objects are already linked?Hey guys,
I have following problem:
I created a kind of voronoi mesh and I now know the position of all vertices and which vertices belong to which polygon.
I know want to treat the vertices and the polygons as classes with handels and link them, so that each vertice knows which are its adjacend vertices and its adjacend polygons and each polygon knows which are the adjacend polygons and the vertices that define their borders.
My classes look like following:
classdef Vertex < handle
properties
position;
neighbour_vertex;
adjacend_polygon;
end
methods
function v = Vertex(pos)
v.position = pos;
v.neighbour_vertex = Vertex.empty(0,0);
v.adjacend_polygon = Polygon.empty(0,0);
end
% link vertex to vertex
function link_v2v(v,neighbour)
v.neighbour_vertex(end+1)=neighbour;
neighbour.neighbour_vertex(end+1)=v;
end
end
end
classdef Polygon < handle
properties
rho
adjacend_vertex;
adjacend_polygon;
end
methods
function p = Polygon(rho)
p.rho=rho;
p.adjacend_vertex = Vertex.empty(0,0);
p.adjacend_polygon = Polygon.empty(0,0);
end
% link polygon to vertex
function link_v2p(p,vertex)
for i=1:length(vertex)
p.adjacend_vertex(end+1)=vertex(i);
vertex(i).adjacend_polygon(end+1)=p;
end
end
% link polygon to edge
% link polygon to polygon
function link_p2p(p)
for i=1:length(p.adjacend_vertex)
for j=1:length(p.adjacend_vertex(i).adjacend_polygon)
if p.adjacend_vertex(i).adjacend_polygon(j)==p || p.adjacend_vertex(i).adjacend_polygon(j)==p.adjacend_polygon(end)
continue
else
p.adjacend_polygon(end+1)=p.adjacend_vertex(i).adjacend_polygon(j);
end
end
end
end
end
end
I linked all object stogether as follows:
pos = vertices;
vertex = Vertex.empty(size(pos,1),0);
polygon=Polygon.empty(size(polygons,1),0);
for i = 1: size(pos,1)
vertex(i) = Vertex(pos(i,:));
end
for i=1:length(edge)
v1=edge(i,1);
v2=edge(i,2);
link_v2v(vertex(v1),vertex(v2));
end
rhos=10^12*random('unif',0.9,1.1,length(polygons),1);
for i=1:size(polygons,1)
polygon(i)=Polygon(rhos(i));
end
for i=1:size(polygons,1)
link_v2p(polygon(i),vertex(polygons{i}));
end
for i=1:length(polygon)
link_p2p(polygon(i));
end
But it doesnt work as planned. Since I find the polygons that are neighbours of a specific polygon, by looking for the already correctly linked vertices of that specific polygon and by looking for the adjacend polygons of those vertices, I double link them.... and since the polygon itsself is a adjacend polygon of its own vertices I link the polygon to itsself which I also do not want.
I got rid of the last point by the first expression in the if statement in the link p2p function in the polygon class, but the second statement that should prevent the double linking does not work...
How can i check if an object that i want to link to another object is already linked to that object?
Best regards
MarcMarc Laubhttps://se.mathworks.com/matlabcentral/profile/authors/9006977-marc-laubtag:se.mathworks.com,2005:Question/5373352020-05-29T10:06:19Z2020-05-29T10:34:41ZFinding specific iteration in a triple for loopI am trying to find the corresponding values of alpha, beta and gamma where my P value is maximum. My code is able to get maximum value of P = 1.9956 but I have no idea how to get the corresponding values of alpha, beta and gamma.
I have attached the question and my current code.
Could anyone help me out. Much appreciated.Jacky Foohttps://se.mathworks.com/matlabcentral/profile/authors/17556780-jacky-footag:se.mathworks.com,2005:Question/5369672020-05-28T23:56:38Z2020-05-29T10:29:37ZHow can I solver this error 'Matrix dimensions must agree.' in ode15s with mass matrix?This is my code
function MMasa_Columna_ELL_Definitivo clc; close all; load('variables') dp1 = polyder(p1); dp3 = polyder(p3); dp2 = polyder(p2); dp4 = polyder(p4); F = 10; x3F = 0; x1F = 0.45; s0 = 3.8; x3s0 = 1; x1s0 = 0; T = 1; %Tiempo de residencia en cada etapa teórica = [min] O = T/60; %Tiempo de residencia en cada etapa teórica = [horas]
x0 = zeros(12,1); %Condiciones iniciales = moles de i/moles totales tspan = [0,1]; %Tiempo de integración = [horas]
Opciones = odeset('MassSingular',@(t,x)Mmasa(t,x,p1,p2,p3,dp1,dp2,dp3),'MStateDependence','strong'); [t,x] = ode23t(@(t,x)modelo(t,x,s0,x3s0,x1s0,F,x3F,x1F,p1,p2,p3,O),tspan,x0,Opciones); plot(t,x(:,:) end function Mdxdt = modelo(~,x,s0,x3s0,x1s0,F,x3F,x1F,p1,p2,p3,O) %Variables de estado x3s1 = x(1); x3s2 = x(2); x3s3 = x(3); x3s4 = x(4); s1 = x(5); s2 = x(6); s3 = x(7); s4 = x(8); r1 = x(9); r2 = x(10); r3 = x(11); r4 = x(12);
%Ecuaciones auxiliares a=zeros(1,length(p1)); a(1,end)=polyval(p3,x3s1); ffx3s1=roots(p1-a); ffx3s1 = ffx3s1(imag(ffx3s1)==0); ffx3s1=ffx3s1(ffx3s1>0 & ffx3s1<0.25);
b=zeros(1,length(p1)); b(1,end)=polyval(p3,x3s2); ffx3s2=roots(p1-b); ffx3s2 = ffx3s2(imag(ffx3s2)==0); ffx3s2=ffx3s2(ffx3s2>0 & ffx3s2<0.25);
c=zeros(1,length(p1)); c(1,end)=polyval(p3,x3s3); ffx3s3=roots(p1-c); ffx3s3 = ffx3s3(imag(ffx3s3)==0); ffx3s3=ffx3s3(ffx3s3>0 & ffx3s3<0.25);
d=zeros(1,length(p1)); d(1,end)=polyval(p3,x3s4); ffx3s4=roots(p1-d); ffx3s4 = ffx3s4(imag(ffx3s4)==0); ffx3s4=ffx3s4(ffx3s4>0 & ffx3s4<0.25);
fsx3s1 = polyval(p2,x3s1); fsx3s2 = polyval(p2,x3s2); fsx3s3 = polyval(p2,x3s3); fsx3s4 = polyval(p2,x3s4);
frx3s1 = polyval(p3,x3s1); frx3s2 = polyval(p3,x3s2); frx3s3 = polyval(p3,x3s3); frx3s4 = polyval(p3,x3s4);
%Ecuaciones diferenciales dn13dt = ((F*x3F + s2*x3s2 - s1*x3s1 - r1*ffx3s1)/O); dn23dt = ((r1*ffx3s1 + s3*x3s3 - s2*x3s2 - r2*ffx3s2)/O); dn33dt = ((r2*ffx3s2 + s4*x3s4 - s3*x3s3 - r3*ffx3s3)/O); dn43dt = ((r3*ffx3s3 + s0*x3s0 - s4*x3s4 - r4*ffx3s4)/O); dn11dt = ((F*x1F + s2*fsx3s2 - s1*fsx3s1 - r1*frx3s1)/O); dn21dt = ((r1*frx3s1 + s3*fsx3s3 - s2*fsx3s2 - r2*frx3s2)/O); dn31dt = ((r2*frx3s2 + s4*fsx3s4 - s3*fsx3s3 - r3*frx3s3)/O); dn41dt = ((r3*frx3s3 + s0*x1s0 - s4*fsx3s4 - r4*frx3s4)/O); dn1dt = ((F + s2 - s1 - r1)/O); dn2dt = ((r1 + s3 - s2 - r2)/O); dn3dt = ((r2 + s4 - s3 - r3)/O); dn4dt = ((r3 + s0 - s4 - r4)/O); Mdxdt = [dn13dt; dn23dt; dn33dt; dn43dt; dn11dt; dn21dt; dn31dt; dn41dt; dn1dt; dn2dt; dn3dt; dn4dt];
end
function M=Mmasa(~,x,p1,p2,p3,dp1,dp2,dp3) %Variables de estado x3s1 = x(1); x3s2 = x(2); x3s3 = x(3); x3s4 = x(4); s1 = x(5); s2 = x(6); s3 = x(7); s4 = x(8); r1 = x(9); r2 = x(10); r3 = x(11); r4 = x(12); %Ecuaciones auxiliares c1=s1+r1*(polyval(dp3,x3s1)/polyval(dp1,x3s1)); c2=s2+r2*(polyval(dp3,x3s2)/polyval(dp1,x3s2)); c3=s3+r3*(polyval(dp3,x3s3)/polyval(dp1,x3s3)); c4=s4+r4*(polyval(dp3,x3s4)/polyval(dp1,x3s4));
c5=s1*polyval(dp2,x3s1)+r1*polyval(dp3,x3s1);
c6=s2*polyval(dp2,x3s2)+r2*polyval(dp3,x3s2);
c7=s3*polyval(dp2,x3s3)+r3*polyval(dp3,x3s3);
c8=s4*polyval(dp2,x3s4)+r4*polyval(dp3,x3s4);
a=zeros(1,length(p1)); a(1,end)=polyval(p3,x3s1);
ffx3s1=roots(p1-a); ffx3s1 = ffx3s1(imag(ffx3s1)==0);
ffx3s1=ffx3s1(ffx3s1>0 & ffx3s1<0.25);
b=zeros(1,length(p1)); b(1,end)=polyval(p3,x3s1);
ffx3s2=roots(p1-b); ffx3s2 = ffx3s2(imag(ffx3s2)==0);
ffx3s2=ffx3s2(ffx3s2>0 & ffx3s2<0.25);
c=zeros(1,length(p1)); c(1,end)=polyval(p3,x3s1);
ffx3s3=roots(p1-c); ffx3s3 = ffx3s3(imag(ffx3s3)==0);
ffx3s3=ffx3s3(ffx3s3>0 & ffx3s3<0.25);
d=zeros(1,length(p1)); d(1,end)=polyval(p3,x3s1);
ffx3s4=roots(p1-d); ffx3s4 = ffx3s4(imag(ffx3s4)==0);
ffx3s4=ffx3s4(ffx3s4>0 & ffx3s4<0.25);
fsx3s1 = polyval(p2,x3s1);
fsx3s2 = polyval(p2,x3s2);
fsx3s3 = polyval(p2,x3s3);
fsx3s4 = polyval(p2,x3s4);
frx3s1 = polyval(p3,x3s1);
frx3s2 = polyval(p3,x3s2);
frx3s3 = polyval(p3,x3s3);
frx3s4 = polyval(p3,x3s4);
%Definición de la matriz de masa
M = [c1 0 0 0 x3s1 0 0 0 ffx3s1 0 0 0
0 c2 0 0 0 x3s2 0 0 0 ffx3s2 0 0
0 0 c3 0 0 0 x3s3 0 0 0 ffx3s3 0
0 0 0 c4 0 0 0 x3s4 0 0 0 ffx3s4
c5 0 0 0 fsx3s1 0 0 0 frx3s1 0 0 0
0 c6 0 0 0 fsx3s2 0 0 0 frx3s2 0 0
0 0 c7 0 0 0 fsx3s3 0 0 0 frx3s3 0
0 0 0 c8 0 0 0 fsx3s4 0 0 0 frx3s4
0 0 0 0 1 0 0 0 1 0 0 0
0 0 0 0 0 1 0 0 0 1 0 0
0 0 0 0 0 0 1 0 0 0 1 0
0 0 0 0 0 0 0 1 0 0 0 1];
end
This is the error that I get
Matrix dimensions must agree.
Error in ode23t>itsolve (line 905) rhs = h * feval(odeFcn,t,y,odeArgs{:}) - M * z;
Error in ode23t (line 537) itsolve(Mtnew,tnew,ynew,znew,gamma,h,L,U,P,Q,R,odeFcn,odeArgs,rtol,...
Error in MMasa_Columna_ELL_Def (line 15) [t,x] = ode23t(@(t,x)modelo(t,x,s0,x3s0,x1s0,F,x3F,x1F,p1,p2,p3,O,1),tspan,x0,Opciones);Olaf Martínezhttps://se.mathworks.com/matlabcentral/profile/authors/18263276-olaf-martineztag:se.mathworks.com,2005:Question/5373592020-05-29T10:26:56Z2020-05-29T10:27:14ZHow to estimate the correct value of "Damping Constant" for Flexible Beams in SimscapeHello,
Reading the Matworks info I notice that damping matrix is defined as proportional by the Damping Constant to the stiffness matrix (the relative damping increase at high frequency).
My question is how to choose the proper value of Damping Constant for different materials.
Thank you and best regardsAlberto Morahttps://se.mathworks.com/matlabcentral/profile/authors/10028030-alberto-moratag:se.mathworks.com,2005:Question/5371792020-05-29T06:46:23Z2020-05-29T10:23:48ZWhat is the BEP in years?Assume the cost of producing a new product is $1,000,000. Then the BEP occurs when net profit from the product
reaches $1,000,000. Let’s say the profit per widget is $1.00 and we’re selling 1,000/day. What is the BEP in years?
Need: BEP = ______ years for a project costing $1,000,000 assuming you are selling 1,000/day with a profit of $1.00 per widget.
Know–How: Equate cost to total money stream.
Solve: 1,000 [widgets/day] x 1.00 [$/widget] x D [days] = $1,000,000. Solving for D gives:
D= 1,000 days = 2.74 yearsElmes Vazquezhttps://se.mathworks.com/matlabcentral/profile/authors/18429034-elmes-vazqueztag:se.mathworks.com,2005:Question/5373552020-05-29T10:23:43Z2020-05-29T10:23:43ZCan I join with 1 variable and 1 value as "keyword"?Hi!
Can I match by dates and by country names?
I've matched by dates, but the code capture all countries.
ThanksMario Diacohttps://se.mathworks.com/matlabcentral/profile/authors/9579842-mario-diacotag:se.mathworks.com,2005:Question/5373032020-05-29T09:36:41Z2020-05-29T10:21:23ZCreate a mask to mask mainland and cloudHello, I have a picture from satellite sentinel 3 where there is cloud and mainland. But I'd like to remove those clouds and mainland to see just the sea and the alga below. Unfortonutaly I have no idea how to code the mask.... Can someone help me please?
Here is the pictureMATHILDE HELBERThttps://se.mathworks.com/matlabcentral/profile/authors/17866907-mathilde-helberttag:se.mathworks.com,2005:Question/5373432020-05-29T10:20:36Z2020-05-29T10:20:36ZEmbed pdf in Excel fileHi everybody.I have a code that generate an excel report. I need inside this code to embed one or more external pdf files into this excel file. This file should be inserted as icon (possibly linking the icon to the cell (not mandatory)). I desire to end up in a situation similar to the one in the attached snip Can you help me?federico atorinhttps://se.mathworks.com/matlabcentral/profile/authors/6424264-federico-atorintag:se.mathworks.com,2005:Question/5370832020-05-29T03:33:41Z2020-05-29T10:20:02ZHow can the code tell if a single test is running instead of the whole test class?I'd like to see more output when I run a single test, vs when I run a whole test class or suite.
Is there a way, either in a test, or in one of the TestClassSetup (setupOnce() or set()) methods that the code can determine this?Randy Strausshttps://se.mathworks.com/matlabcentral/profile/authors/18013422-randy-strausstag:se.mathworks.com,2005:Question/5371152020-05-29T04:30:21Z2020-05-29T10:19:50ZHow to solve this nonlinear simultaneous equation?%For C1
lambda1 = [60.21, 41.58, 9.11, 8.71, 3.83, 3.74, 18.06]
r1 = poissrnd(lambda1)
%For C2
lambda2 = [41.58, 60.21, 8.71, 9.11, 3.74, 3.83, 18.06]
r2 = poissrnd(lambda2)
%Designed training sequences x1 and x2
x1 = [1,1,1,0,0,0,0,1,0,1,0,1,1,0,0,1] ;
x2 = [1,1,1,0,1,0,0,0,1,1,1,0,0,0,0,1] ;
%X[3] to X[16]
X3 = [1 1 1 1 1 1 1]' ;
X4 = [0 0 1 1 1 1 1]' ;
X5 = [0 1 0 0 1 1 1]' ;
X6 = [0 0 0 1 0 0 1]' ;
X7 = [0 0 0 0 0 1 1]' ;
X8 = [1 0 0 0 0 0 1]' ;
X9 = [0 1 1 0 0 0 1]' ;
X10 = [1 1 0 1 1 0 1]' ;
X11 = [0 1 1 1 0 1 1]' ;
X12 = [1 0 0 1 1 1 1]' ;
X13 = [1 0 1 0 0 1 1]' ;
X14 = [0 0 1 0 1 0 1]' ;
X15 = [0 0 0 0 1 0 1]' ;
X16 = [1 1 0 0 0 0 1]' ;
%X,a 7x14 matrix
X = [X3,X4,X5,X6,X7,X8,X9,X10,X11,X12,X13,X14,X15,X16];
%C, a 7x2 matrix
C = [r1; r2]' ;
%Y, a 14x2 matrix
Y = X'*C ;
%Yd = Poiss(Y) (at equation (8))
Yd = poissrnd(Y)
%y1, a 14x1 matrix ; y2, a 14x1 matrix
y1 = Y(:,1)
y2 = Y(:,2)
%Least Square Estimate of C
Cls = (inv(X*X'))*(X*Yd)
% To set to zero all the negative entries of C
Cls1 = max(Cls,0)
%Mean square error of LS C and C
MSE = mean((C - Cls1).^2)
syms C1 C2 C3 C4 C5 C6 C7
(((y1(1))/(C1 + C2 + C3 + C4 + C5 + C6 + C7))*X3) + (((y1(2))/C3 + C4 + C5 + C6)*X4) + ...
(((y1(3))/C2 + C5 + C6 + C7)*X5) + (((y1(4))/C4 + C7)*X6) + (((y1(5))/C6 + C7)*X7) + ...
(((y1(6))/C1 + C7)*X8) + (((y1(7))/C2 + C3 + C7)*X9) + (((y1(8))/C1 + C2 + C4 + C5 + C7)*X10) + ...
(((y1(9))/C2 + C3 + C4 + C6 + C7)*X11) + (((y1(10))/C1 + C4 + C5 + C6 + C7)*X12) + ...
(((y1(11))/C1 + C3 + C6 + C7)*X13) + (((y1(12))/C3 + C5 + C7)*X14) + (((y1(13))/C5 + C7)*X15) + ...
(((y1(14))/C1 + C2 + C7)*X16) == (X3 + X4 + X5 + X6 + X7 + X8 + X9 + X10 + X11 +X12 + X13 + X14 + X15 + X16)Eric Chuahttps://se.mathworks.com/matlabcentral/profile/authors/12596882-eric-chuatag:se.mathworks.com,2005:Question/5371712020-05-29T06:24:59Z2020-05-29T10:19:12Zfitgmdist for loop; nested for loop, combine array of different sizesHi all,
Please help me. Please. This research student will thank you immensely.
Here's the scenario: I have two populations (main and sub). The sub population is 10% of the main population. The mean (mu) and sigma(std) of these two populations can change, but have certain predefined boundaries. Right now, I am only changing the sigma of the main population and keeping the sigma of the sub population, and the mean of both populations constant.
What I want: I want to use fitgmdist/GMModels/Gaussian distribution to be able to identify that there are indeed two components in that set of data. In other words, I am trying to see for what sigma_main values does the model ouput two components (numComponents = 2). Right now, I have a model that iterates through my sigmamain values (0.1:0.05:1) and goes through varying GMModels to find the one with the better AIC (least error) and outputs the numComponents for every sigma_main value, and then sigma_main vs numComponents is plotted. At least, that's what I think.
Here's my code:
%% define known constants
% rng(0,'twister')
n_main = 100000;
n_sub = 10000;
%sigma_main = 0.1;
sigma_sub = 0.1;
mu_main = 1;
mu_sub =3;
%% change sigma_main values and run model
sigmamain_val = 0.1:0.05:1;
outputData = zeros(length(sigmamain_val), 2); % create an output array for (length sigma_sub),numComponents
for i = 1:length(sigmamain_val)
sigmamain_pos = randi(length(sigmamain_val));
sigma_main = sigmamain_val(sigmamain_pos);
y = sigma_main.*randn(n_main,1) + mu_main; %10^6 SKBr3 cells
y2 = sigma_sub.*randn(n_sub,1) + mu_sub; %100,000 MDA MB 231
C = cat(1, y, y2);
AIC = zeros(1,4); % create an ouput array for AIC
GMModels = cell(1,4);
options = statset('MaxIter',00); % add optitons here to better/refine the model
for k = 1:4
GMModels{k} = fitgmdist(C,k);
AIC(k)= GMModels{k}.AIC;
end
[minAIC,numComponents] = min(AIC);
outputData(i,1) = sigma_main;
outputData(i,2) = numComponents;
%BestModel = GMModels{numComponents}
BestModel = GMModels{outputData(i,2)};
end
%% plot sigma main vs numComponents
figure(3)
plot(outputData(:,1),outputData(:,2))
xlabel('sigma main')
ylabel('numComponents')
Btw: the idea for this model with AIC is based off: https://www.mathworks.com/help/stats/fitgmdist.html
Here's the problem:
For starters: The code for y & y2, which are for my main and sub population respectively, only take into account the very last sigma value.
A bigger problem is that sometimes, my code picks a sigma_main value twice (i.e 0.8) and the number of components is sometimes different even though they are the same sigma_main value.
Also, I would like to ouput a "BestModel" or 1x1 gmdistrinution for every sigma_main value instead of just the last one and I don't know how to incorporate that in my for loop.
What I think: I need to go through sigma_main values in order (i.e only write "sigma_main = i" inside the for loop) so that values don't get repeated, but then my y and y2 cannot b concatenated (C = cat(1, y,y2) because my sigma_main value will be 19x1 instead of just one number.
To outut a BestModel for every sigma_main, I need to create an empty/zeroes array before but I don't know ehat type to do that for.
Please, please help me. I have stayed up two nights doing this and I really don't know how to move forward. It might be really simple, but I might be overthinking it. Elizabeth Cardonahttps://se.mathworks.com/matlabcentral/profile/authors/10795179-elizabeth-cardonatag:se.mathworks.com,2005:Question/5373312020-05-29T10:04:19Z2020-05-29T10:16:31Zdifference of image histogramshello, in Matlab is equal to do the histogram of difference of two grayscale images and the difference of the two histograms of the images? How to perform the difference of two histograms and plot the negative values of this difference?
thank you for the help,
Giuseppegiuseppe catarinellahttps://se.mathworks.com/matlabcentral/profile/authors/17466933-giuseppe-catarinellatag:se.mathworks.com,2005:Question/5342582020-05-26T14:57:11Z2020-05-29T10:16:16ZHow to compute lognormal distributionHi everyone,
I have 19 years of data and I have to compute lognormal distribution of each month of each year. I've already computed monthly average values and monthly standard deviation on each year. I know the more quickly way to do this kind of operation is for loop but I'm a beginner on Matlab and i don't know how to use for loop i these situations. I think that I need of two for loop, one with index on the years and the other with index on the months but I don't know. I've done the code below that it is manual and too much long. I need to make it authomatic. Thank you in advance!
format long g
folder = 'D:\Valerio\data\IPCC_midcent\RCP4.5\BCC_CSM\BCC_CSM.xlsx';
file = xlsread(folder);
dt = datetime([file(:,1:3) file(:,4)/1E4 repmat([0 0],size(file,1),1)]);
tt = timetable(dt, file(:,5:end));
data = tt.Var1;
% file(:, 3:4) = []; % delete day and hour columns as they are not important for yearly mean
[grps, Years, Months] = findgroups(file(:,1), file(:,2));
result_mean = splitapply(@(x) mean(x, 1), file(:,5:end), grps);
result_mean = [Years Months result_mean];
result_std = splitapply(@(x) std(x, [], 1), file(:,5:end), grps);
result_std = [Years Months result_std];
TR1 = timerange('01-Jan-2026 00:00:00','01-Feb-2026 00:00:00');
tt_TR1 = tt(TR1,:);
Hs1 = tt_TR1.Var1(:,1);
Tp1 = tt_TR1.Var1(:,2);
d_Hs1 = lognpdf(Hs1,result_mean(1,3),result_std(1,3));
d_Tp1 = lognpdf(Tp1,result_mean(1,4),result_std(1,4));
TR2 = timerange('01-Feb-2026 00:00:00','01-Mar-2026 00:00:00');
tt_TR2 = tt(TR2,:);
Hs2 = tt_TR2.Var1(:,1);
Tp2 = tt_TR2.Var1(:,2);
d_Hs2 = lognpdf(Hs2,result_mean(2,3),result_std(2,3));
d_Tp2 = lognpdf(Tp2,result_mean(2,4),result_std(2,4));
TR3 = timerange('01-Mar-2026 00:00:00','01-Apr-2026 00:00:00');
tt_TR3 = tt(TR3,:);
Hs3 = tt_TR3.Var1(:,1);
Tp3 = tt_TR3.Var1(:,2);
d_Hs3 = lognpdf(Hs3,result_mean(3,3),result_std(3,3));
d_Tp3 = lognpdf(Tp3,result_mean(3,4),result_std(3,4));
TR4 = timerange('01-Apr-2026 00:00:00','01-May-2026 00:00:00');
tt_TR4 = tt(TR4,:);
Hs4 = tt_TR4.Var1(:,1);
Tp4 = tt_TR4.Var1(:,2);
d_Hs4 = lognpdf(Hs4,result_mean(4,3),result_std(4,3));
d_Tp4 = lognpdf(Tp4,result_mean(4,4),result_std(4,4));
TR5 = timerange('01-May-2026 00:00:00','01-Jun-2026 00:00:00');
tt_TR5 = tt(TR5,:);
Hs5 = tt_TR5.Var1(:,1);
Tp5 = tt_TR5.Var1(:,2);
d_Hs5 = lognpdf(Hs5,result_mean(5,3),result_std(5,3));
d_Tp5 = lognpdf(Tp5,result_mean(5,4),result_std(5,4));
Valerio Gianfortehttps://se.mathworks.com/matlabcentral/profile/authors/16843878-valerio-gianfortetag:se.mathworks.com,2005:Question/5372192020-05-29T07:29:32Z2020-05-29T10:11:10ZPlotting graph of an equationHi, hope that someone can help me on this. I want to plot a graph of this equation:
I have fix value of B,w and d. x-axis will be inner angle and y-axis will be outer angle.
Thank you in advance for any assistance provided.Jaydenhttps://se.mathworks.com/matlabcentral/profile/authors/18627222-jaydentag:se.mathworks.com,2005:Question/5372632020-05-29T08:23:47Z2020-05-29T10:09:22ZHow to add a vector to another vector in for loopHi,
I have a code calculating hourly temperatures in a system over a year in a for loop i=1:8760 (8760 is the number of hours in a year).
I would like to see how the hourly temperature level develop over ten years. I was thinking to put my already existing code into a new for loop with j=1:10, but I struggle with how wrap it up to a long vector with 87600 elements at the end. (not taking leap years into account). The code at this point is like this:
years=10;
T_tot=zeros(years,1);
for j=1:years
for i=1:8760
Tvec(i)=%code
end
T_tot(j)=Tvec;
end
I see that my code have some issues as I add several elements to my yearsx1 vector. How can this be improved so that i get my hourly values over 10 years (1x87600 or opposite)?Vilde Eikeskoghttps://se.mathworks.com/matlabcentral/profile/authors/6822276-vilde-eikeskogtag:se.mathworks.com,2005:Question/5373392020-05-29T10:09:20Z2020-05-29T10:09:20ZSymsum iteration over non-symbolic array problemHello,
I want to generate the sum of a series of log functions l(x) that have two parameters (n, g).
n = 5;
g = 0:4; %example array
syms l(x) k
l(x) = g*log(x)+(n-g)*log(1-x);
Ls(x) = symsum(l,k,1,n);
One parameter (g) is always an array of varying size. l(x) generates a function for each element of g as expected. I would like to get the sum equation for all l(x), in this case:
Ls(x) = 15*log(1-x)+10*log(x)
However for symsum, Ls produces a k-times summation of l(x) for each element of g separately:
Ls(x) =
[ 25*log(1 - x), 20*log(1 - x) + 5*log(x), 15*log(1 - x) + 10*log(x), 10*log(1 - x) + 15*log(x), 5*log(1 - x) + 20*log(x)]
I was under the impression I could use symbolic equations and symsum here because I wanted the final equation.
Do you have any suggestion on how to approach this since I can't use k to index?Stefanhttps://se.mathworks.com/matlabcentral/profile/authors/4894982-stefantag:se.mathworks.com,2005:Question/5372672020-05-29T08:28:57Z2020-05-29T10:09:01ZODE error message "Error using exist The first input to exist must be a string scalar or character vector"this is my code
syms no(k1,k2,k3,k_1,k_2,k_3,o2,n2,o,h2o,oh,h,t)
n=(k1*o*n2+k_2*no*o+k_3*no*h)/(k_1*no+k2*o2+k3*oh);
eqn1=k1*o*n2-k_1*no*n+k2*n*o2-k_2*no*o+k3*n*oh-k_3*no*h;
fin = diff(no,t)==eqn1;
tspan = [0 10];
i=[0 0];
ra=ode45(fin,tspan,i)Abdelrahman Eldalyhttps://se.mathworks.com/matlabcentral/profile/authors/15707120-abdelrahman-eldalytag:se.mathworks.com,2005:Question/5112432020-03-17T04:13:02Z2020-05-29T10:08:28ZSensitivity analysis of odes Hi All,
I'm solving a dynamical system uisng ode15s. The system has a lot of parameters and I'd like to perform sensitivity analysis.
I found this on file exchange https://in.mathworks.com/matlabcentral/fileexchange/1480-sensitivity-analysis-for-odes-and-daes
Is there any other toolbox available in MATLAB for performing sensitivity analysis of odes?
Thanks
Deepa Maheshvarehttps://se.mathworks.com/matlabcentral/profile/authors/8575091-deepa-maheshvaretag:se.mathworks.com,2005:Question/5372952020-05-29T09:32:38Z2020-05-29T10:05:55Zabout taylor series and user defined functionI want mfile under the following conditions.
The Taylor series development for cos x is as follows.
Write a user defined function that calculates Sn so that the error of the actual cos(x) value at each stage of the water supply can be calculated as ㅣSn - cos xㅣ, and the error of x is less than 0.0001.
1.First line must 'function [sn,error] = cosine(x)'
2.When you enter the X value, you must calculate Sn when the error falls below 0.0001 for the first time and assign it to the Sn variable, calculate the error ㅣSn - cos xㅣ, and create a function called error.Harry Kanehttps://se.mathworks.com/matlabcentral/profile/authors/18637062-harry-kanetag:se.mathworks.com,2005:Question/5352382020-05-27T10:01:02Z2020-05-29T10:04:25Zerror when using 'find' functionHi
i actually want to find the first the first and last non zero row to avoid the edge effects and enforce them to zero for my analysis. But when i try running the code, i get this error - 'Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 0-by-1'. Here is the part of code that gives the error.
idxo1 = zeros(size(U_col,2),size(U_col,3));
idxo2 = zeros(size(U_col,2),size(U_col,3));
for j =1:size(U_col,3)-1
for k = 1:size(U_col,2)-1
idxo1(k,j) = find(EffectiveDivergence(:,k,j), 1, 'first');
idxo2(k,j) = find(EffectiveDivergence(:,k,j), 1, 'last');
end
end
5 and 6th line are giving the errors.
ThanksSunil S Hosakotihttps://se.mathworks.com/matlabcentral/profile/authors/15221858-sunil-s-hosakotitag:se.mathworks.com,2005:Question/5373232020-05-29T09:59:31Z2020-05-29T09:59:31ZFrequency interpretation of wpspectrum I am currently working on an implementation of a wavelet-transformation.
The example has two sin-signals with 1024 Samples of 50 and 500 Hz. FS = 16 kHz, so fg = 8kHz. I am decomposing it with 8 levels, with a db4-wavelet manually by using cconv (circular convolution) with the wfilters of low and high filters of db4 and downsampling it after each convolution. So I get a 256 entry cell array (256 terminal nodes) with 4 entries per cell - works properly imo. So far so good.
Comparing this implementation to the wpdec function of MATLAB, it uses a normal convolution, which results to more values on each level of decomposition, which is fine because of the size of the filter (1024 + 8 (db4-length) -1 = 1033 / 2 = 516 values instead of 512 with cconv). This leads to 10 values for each terminal node on level 8.
Comparing the energy of both implementations, they both do have high energy values at subband 2 (31.25-62.5 Hz) and subband 25 ( around 800 Hz). However then plotting the Frequencies of wpspectrum with the result of wpdec leads to the correct frequencies at band 2 and band 16 (50 and 500), while I would think that it had to be 50 and 800 by the results of the energy. wpspectrum uses the following 3 steps:
Extract the wavelet packet coefficients corresponding to the terminal nodes. Take the absolute value of the coefficients.
Order the wavelet packet coefficients by frequency ordering.
Determine the time extent on the original time axis corresponding to each wavelet packet coefficient. Repeat each wavelet packet coefficient to fill in the time gaps between neighboring wavelet packet coefficients and create a vector equal in length to node 0 of the wavelet packet tree object.
I am calculating the teager-operations of the coefficients of the terminal nodes - these are absolute values
In my opinion they are already frequency ordered cause the 8 times low-pass filtered signal should be placed in subband 1 and so on.
I dont really know what is suggested here, but all subbands have exactly 4 values and as the input signal is stationary I don't see a need for gap-filling. Am I mistaken here?
However, wpspectrum results in finding the 500 Hz frequency and I have no idea how it is able to. What has to be done with the resulting cell array to detect the correct frequencies?
Thanks in advance. I can provide code for further investigation aswell.Kai Blumhttps://se.mathworks.com/matlabcentral/profile/authors/7792815-kai-blum