https://www.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions2020-08-10T23:19:20Ztag:www.mathworks.com,2005:Question/5778312020-08-10T18:52:06Z2020-08-10T23:19:20ZPatch plot z-values colorbar not correct Hello,
I have a 'patch' plot with x, y, and z-values. A 2x2 sublot is desired with a single colorbar on the right. The values of the colorbar should be from 0 to 1. However, the values in the plot are an order of magnitude off. My largest value in the upper left plot, for example, is somewhere around 0.08. But, the figure is plotting the value as 0.8.
I've attached my plotting script (below) and the variables needed (attached).
Any ideas?
Thanks.
% Combined JER winter/summer 2019 NORMALIZED plot
fig = figure; % figure 6
subplot(2, 2, 1) % JER Summer 2019
patch(X, Y, norm_DSVD_sum2019_JER,'HandleVisibility','off');
title('Summer 2019, Las Cruces, NM', 'FontSize', 12)
% xlabel('Raindrop Size [mm]', 'FontSize', 12)
% ylabel('Raindrop Speed [m/s]', 'FontSize', 12)
xlim([0 8])
ylim([0 11])
xticks([0 1.25 2.5 5.0 8.0 10.0 20.0 26.0]) % These ticks delineate changes in class spread.
yticks([0 1.0 2.0 4.0 8.0 11.0 16.0 22.4]) % These ticks delineate changes in class spread.
% c = colorbar;
% c.Label.String = 'Raindrop Count';
% c.Label.FontSize = 12;
% colormap('jet')
grid off
hold on
p1 = plot(X, vD_AfGK, 'r', 'LineWidth', 2); % This plots the Atlas empirical v(D) line from Gunn-Kinzer's data.
p2 = plot(X, vD_AU, 'r--', 'Linewidth', 2, 'LineStyle', '--'); % This plots the Atlas and Ulbrich, 1977 v(D) line.
p3 = plot(X, vD_VD, 'r', 'Linewidth', 2, 'LineStyle', ':'); % This plots the van Dijk et. al. (2002) v(D) line.
% lgd = legend([p1(1) p2(1) p3(1)],'Atlas et. al., 1973', 'Atlas and Ulbrich, 1977', 'van Dijk et. al., 2002', 'Location', 'southeast');
% lgd.FontSize = 12;
% lgd.Title.String = 'Droplet Size/Velocity Relationships';
subplot(2, 2, 2) % JER Winter 2019
patch(X, Y, norm_DSVD_win2019_JER,'HandleVisibility','off');
title('Winter 2019, Las Cruces, NM', 'FontSize', 12)
% xlabel('Raindrop Size [mm]', 'FontSize', 12)
% ylabel('Raindrop Speed [m/s]', 'FontSize', 12)
xlim([0 8])
ylim([0 11])
xticks([0 1.25 2.5 5.0 8.0 10.0 20.0 26.0]) % These ticks delineate changes in class spread.
yticks([0 1.0 2.0 4.0 8.0 11.0 16.0 22.4]) % These ticks delineate changes in class spread.
% c = colorbar;
% c.Label.String = 'Raindrop Count';
% c.Label.FontSize = 12;
% colormap('jet')
grid off
hold on
p1 = plot(X, vD_AfGK, 'r', 'LineWidth', 2); % This plots the Atlas empirical v(D) line from Gunn-Kinzer's data.
p2 = plot(X, vD_AU, 'r--', 'Linewidth', 2, 'LineStyle', '--'); % This plots the Atlas and Ulbrich, 1977 v(D) line.
p3 = plot(X, vD_VD, 'r', 'Linewidth', 2, 'LineStyle', ':'); % This plots the van Dijk et. al. (2002) v(D) line.
% lgd = legend([p1(1) p2(1) p3(1)],'Atlas et. al., 1973', 'Atlas and Ulbrich, 1977', 'van Dijk et. al., 2002', 'Location', 'southeast');
% lgd.FontSize = 12;
% lgd.Title.String = 'Droplet Size/Velocity Relationships';
subplot(2, 2, 3) % SFL Summer 2019
patch(X, Y, norm_DSVD_sum2019_SFL,'HandleVisibility','off');
title('Summer 2019, Mesa, AZ', 'FontSize', 12)
% xlabel('Raindrop Size [mm]', 'FontSize', 12)
% ylabel('Raindrop Speed [m/s]', 'FontSize', 12)
xlim([0 8])
ylim([0 11])
xticks([0 1.25 2.5 5.0 8.0 10.0 20.0 26.0]) % These ticks delineate changes in class spread.
yticks([0 1.0 2.0 4.0 8.0 11.0 16.0 22.4]) % These ticks delineate changes in class spread.
% c = colorbar;
% c.Label.String = 'Raindrop Count';
% c.Label.FontSize = 12;
% colormap('jet')
grid off
hold on
p1 = plot(X, vD_AfGK, 'r', 'LineWidth', 2); % This plots the Atlas empirical v(D) line from Gunn-Kinzer's data.
p2 = plot(X, vD_AU, 'r--', 'Linewidth', 2, 'LineStyle', '--'); % This plots the Atlas and Ulbrich, 1977 v(D) line.
p3 = plot(X, vD_VD, 'r', 'Linewidth', 2, 'LineStyle', ':'); % This plots the van Dijk et. al. (2002) v(D) line.
% lgd = legend([p1(1) p2(1) p3(1)],'Atlas et. al., 1973', 'Atlas and Ulbrich, 1977', 'van Dijk et. al., 2002', 'Location', 'southeast');
% lgd.FontSize = 12;
% lgd.Title.String = 'Droplet Size/Velocity Relationships';
subplot(2, 2, 4) % SFL Winter 2019
patch(X, Y, norm_DSVD_win2019_SFL,'HandleVisibility','off');
title('Winter 2019, Mesa, AZ', 'FontSize', 12)
% xlabel('Raindrop Size [mm]', 'FontSize', 12)
% ylabel('Raindrop Speed [m/s]', 'FontSize', 12)
xlim([0 8])
ylim([0 11])
xticks([0 1.25 2.5 5.0 8.0 10.0 20.0 26.0]) % These ticks delineate changes in class spread.
yticks([0 1.0 2.0 4.0 8.0 11.0 16.0 22.4]) % These ticks delineate changes in class spread.
% c = colorbar;
% c.Label.String = 'Raindrop Count';
% c.Label.FontSize = 12;
% colormap('jet')
grid off
hold on
p1 = plot(X, vD_AfGK, 'r', 'LineWidth', 2); % This plots the Atlas empirical v(D) line from Gunn-Kinzer's data.
p2 = plot(X, vD_AU, 'r--', 'Linewidth', 2, 'LineStyle', '--'); % This plots the Atlas and Ulbrich, 1977 v(D) line.
p3 = plot(X, vD_VD, 'r', 'Linewidth', 2, 'LineStyle', ':'); % This plots the van Dijk et. al. (2002) v(D) line.
lgd = legend([p1(1) p2(1) p3(1)],'Atlas et. al., 1973', 'Atlas and Ulbrich, 1977', 'van Dijk et. al., 2002', 'Position', [.72 .12 .14 .1]);
lgd.FontSize = 6.5;
lgd.Title.String = 'Droplet Size/Velocity Relationships';
sgt = sgtitle('Normalized Drop Size and Velocity Distributions');
sgt.FontSize = 20;
ax = axes(fig);
yyaxis(ax, 'left');
han = gca;
han.Visible = 'off';
set(gca, 'ycolor', 'k')
han.XLabel.Visible = 'on';
han.YLabel.Visible = 'on';
xlabel('Raindrop Size [mm]')
ylabel('Raindrop Speed [m/s]')
yyaxis(ax, 'right');
c = colorbar('Position', [0.9214, 0.0935, 0.0165, 0.8147]);
c.Label.String = 'Normalized Raindrop Count';
c.Label.FontSize = 12;
colormap('jet')
han.YLabel.Visible = 'on';Eric Escotohttps://www.mathworks.com/matlabcentral/profile/authors/7056746tag:www.mathworks.com,2005:Question/5778942020-08-10T23:18:20Z2020-08-10T23:18:20ZHow to reduce decimal point in .dat file?I use the following code:
format long g
A=round(randperm(10,8));
save 'A.dat' A -ascii
output in .dat file:
9.0000000e+00 2.0000000e+00 4.0000000e+00 7.0000000e+00 1.0000000e+00 8.0000000e+00 5.0000000e+00 1.0000000e+01
However, it should be:
9 2 4 7 1 8 5 10
or
9.00 2.00 4.00 7.00 1.00 8.00 5.00 10.00
Please let me know how I can solve the problem.
SMhttps://www.mathworks.com/matlabcentral/profile/authors/15736394tag:www.mathworks.com,2005:Question/5775942020-08-10T11:42:07Z2020-08-10T23:16:57ZDynamic uimenu dropdown list in figure tool barI would like to add a dynamic dropdown list of menu items on a figure tool bar the initail list will consist of,
s_commands = {'!LED1','!LED2','!LEDT1','!LEDT2','!RGBW1','!RGBW2',...
'!POSRST','!POSSTR','!NEXT','!SLEEP','!WAKE','!POS','!GO',...
'!HELP','!VERS','!IDN'};
The number of list elements will vary, with between 5 to 20 elements. The following does not seem to work, am I missing something subtle?
figDialog = figure('Toolbar','none');
menuDialog = uimenu('Text','Commands');
menuItems = uidropdown(menuDialog,'Text',s_commands);
I'm a bit new as I havent done any Matlab coding for over 6 years and am unable to find a suitable answer.
Thanks in advance.Antonio Bencihttps://www.mathworks.com/matlabcentral/profile/authors/3767928tag:www.mathworks.com,2005:Question/5767092020-08-07T21:02:28Z2020-08-10T23:15:14Zstandard deviation and mean across specific columns of a 3D matrix I have multiple excel files that I need to analyze. The data is voltage vs time, and the size of each file is 700x216 double. Each file has multiple tests and multiple trials for each test. I need to average the trials for each test across rows. Then I need to compare the averaged data between tests(files). I can import all the files I need with a for loop, construct a 3D matrix, and get the mean of all values across tests. Is there a way to average across specific rows for all tests and run statistics such as standard deviation across the averaged data in a 3D matrix? Is a 3D matrix the best approach for this?
% 3D matrix
mtx = cat(3,(data{:,1}));
%mean of matrix
Mmtx = mean(mtx,3);
% tried this but only gave me the average of the first data set
MmtxT1 = mean(mtx(:,[2 3 4 5]),2);Michael Grybkohttps://www.mathworks.com/matlabcentral/profile/authors/11905280tag:www.mathworks.com,2005:Question/5778912020-08-10T23:13:27Z2020-08-10T23:13:27ZAdding time (time stamp) to observationsHi I have a quesion regarding the creation of a time variable with increments of every 10 seconds ( I am trying to do a time series graph). I have tried with datetime and duration with no luck. The time of the sampling shoulf cover in theory the 161,052 observations. Any help will be appreciated.
D = duration(4,00:00,10) %% I tried this trying to get the increments of a duration period of 4 hours in increments of 10 secondsdesert_scientist90https://www.mathworks.com/matlabcentral/profile/authors/15423469tag:www.mathworks.com,2005:Question/5778882020-08-10T23:12:58Z2020-08-10T23:12:58ZHow to optimize machine-learning model exported from regression learner app?Thank you for visiting this question.
Now I've tried to optimize my machine-learning model exported from regression learner app.
This model has 27 inputs, and there is no certain numerical equation for result.
I googled keywords such as optimization of trained model, or optimization using GAMS, but I've failed to find proper items.
Please help me !Manheehttps://www.mathworks.com/matlabcentral/profile/authors/14839810tag:www.mathworks.com,2005:Question/5778852020-08-10T23:09:24Z2020-08-10T23:10:47ZPlot a filled black circle on a certain backgroundI have a 344*344 grey image with noise only. Now I want to plot a filled black circle in the middle of that gray image as background.
How can I achieve that? And I hope I can also adjust the size (scale) of the filled black circle in the middle of the image.
Thanks so much!!Chenhttps://www.mathworks.com/matlabcentral/profile/authors/5673852tag:www.mathworks.com,2005:Question/5778822020-08-10T23:09:12Z2020-08-10T23:09:12ZHow to concatenate cells in mat file under each other?Hello, I have a .mat file which is comprised of 255 cells. Each cell is a 14 by 65 table. I need to concatenate the tables under each other so that I can have a 14*225 by 65 table at the end. Does anyone know how I can do so in Matlab?Mohammad Rashedihttps://www.mathworks.com/matlabcentral/profile/authors/19104414tag:www.mathworks.com,2005:Question/5778792020-08-10T23:07:38Z2020-08-10T23:07:38ZError Message: Output argument "I" (and maybe others) not assigned during call to "simpsons".Hi, so I recently wrote a function
function I = simpsons(f,M,a,b)
h = (b-a)/(M-1);
f = @(x) x;
if rem(M,2) == 0
simpsons1(f,M,a,b)
elseif rem(M,3) == 0
simpsons2(f,M,a,b)
else
simpsons2(f,4,a,3*h) + simpsons1(f,M-3,3*h,b)
end
However, when I call the function in another script, I get the message Output argument "I" (and maybe others) not assigned during call to "simpsons".
This is my script
%i calculating pressure at a given depth
p0 = 101325;
g = 9.81;
for i = 1:1:43
I = 1;
I = simpsons(1,43,0,z(i));
pz = I;
pzm(i) = p0 + I*g;
endMohammad Sirajhttps://www.mathworks.com/matlabcentral/profile/authors/13410386tag:www.mathworks.com,2005:Question/5776092020-08-10T12:00:36Z2020-08-10T22:54:30ZHow to apply a random Crossover (Arithmetic/Scattered/Two-point) in Genetic Algorithm using auto-generated file from Optimization Toolbox ?I have prepared a code in MATLAB with optimization toolbox which seems to be giving fair results for different optimization functions but at present, accuracy is highly dependent on the type of crossover selected.
To take advantage of different crossover and to improve efficiency, i want to apply a random crossover after every iteration i.e. any of Arithmetic, Scattered or Two-point. How can I do that ?Ankur Shahhttps://www.mathworks.com/matlabcentral/profile/authors/14208584tag:www.mathworks.com,2005:Question/5166762020-04-09T16:07:51Z2020-08-10T22:51:52Zwrite 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://www.mathworks.com/matlabcentral/profile/authors/18061673tag:www.mathworks.com,2005:Question/5778732020-08-10T22:43:33Z2020-08-10T22:51:41ZHow to use not equal in for loopIs it possiable to use ~= in for loop like
for t ~= 1
xxx
xxx
xxx
endKaiyu Niehttps://www.mathworks.com/matlabcentral/profile/authors/18876342tag:www.mathworks.com,2005:Question/5773062020-08-09T18:34:43Z2020-08-10T22:50:25ZHow to convert tif stack to dcm series?I have a tif file that contains 1813 pages (images). I want to convert these to DICOM files within a single series. Currently, the code I am using writes over the .dcm file during each loop. How can I fix this?
fname = 'Sample19.tif';
info = imfinfo(fname);
imageStack = [];
numberOfImages = length(info);
for k = 1:numberOfImages
currentImage = imread(fname, k, 'Info', info);
dicomwrite(currentImage,'gear.dcm')
imageStack(:,:,k) = currentImage;
end Alena Schwartzhttps://www.mathworks.com/matlabcentral/profile/authors/12885026tag:www.mathworks.com,2005:Question/5778762020-08-10T22:43:46Z2020-08-10T22:43:46ZIs there a way to input direction in matlab UIHi, I would like to let users to click on an image and input the normal vector of the pixel. Is there a way to let the users input the direction elegantly? For example a sphere for users to rotate or something like that?
Thank you very much.xingze tianhttps://www.mathworks.com/matlabcentral/profile/authors/11012585tag:www.mathworks.com,2005:Question/5778702020-08-10T22:43:12Z2020-08-10T22:43:12ZWrite to an already opened Excel fileThe following MATLAB code works well for writing
eActiveSheetRange.Value
to the range
eActiveSheetRange
However, I have to keep the respective Excel file not opened by any application to make the writing process successful.
So, is there any way to keep the Excel file opened by, for example, Excel while making the MATLAB able to write to it without throwing errors and watch the new values be written?
excel = actxserver('Excel.Application');
wbooks = excel.Workbooks;
eWorkbook = wbooks.Open('C:\Users\Diaa\Desktop\test.xlsx');
eSheets = excel.ActiveWorkBook.Sheets;
sheet1 = eSheets.get('Item',1);
sheet1.Activate
eActiveSheetRange = get(excel.Activesheet,'Range','B1');
eActiveSheetRange.Value = 15;
eWorkbook.Save
excel.Quit
excel.deleteDiaahttps://www.mathworks.com/matlabcentral/profile/authors/3426444tag:www.mathworks.com,2005:Question/5778582020-08-10T21:21:09Z2020-08-10T22:41:29ZError: Unable to perform assignment because the left and right sides have a different number of elements. M = 64; %Number of subcarriers
K = 4; %Overlapping factor
y = [-0.23514695 -sqrt(2)/2 -0.97195983 1 0.97195983 sqrt(2)/2 0.23514695];
T = M;
l = K*T;
a = K*M;
t = -a/2:a/(2-1);
h = zeros(1,10000);
size(h);
for k = -3:3
for x=0:6
r = k+3;
abc=size((y(x+1)^2)*cos((2*k*pi*t)/l));
h(r+1)= (y(x+1)^2)*cos((2*k*pi*t)/l); Error here
end
end
h = [h{:}];
h = h(1)+h(2)+h(3)+h(4)+h(5)+h(6)+h(7);
a = 1+ (2*h);
figure(1)
plot (a)
xlabel('t')
ylabel('h(t)')Sara Nasirhttps://www.mathworks.com/matlabcentral/profile/authors/19021769tag:www.mathworks.com,2005:Question/5778672020-08-10T22:28:25Z2020-08-10T22:28:25Zfeof command for multiple matrixes in one fileHi! Im worried about how to write a code, so to read a file which includes a matrix with joint coordinated, member incidences and joint loads with space line between them. its feof with while the command that i need so to choose each time the matrix (which starts from a different line each time) i want to read and do the controls?VeriumBshttps://www.mathworks.com/matlabcentral/profile/authors/9887765tag:www.mathworks.com,2005:Question/5778642020-08-10T22:20:13Z2020-08-10T22:27:50ZFinding min values of third column for rows with similar valuesHi,
I have a Table
2.0000 0 3.1971
1.0000 0 3.1971
3.0000 0 6.4662
1.0000 0 6.4662
3.0000 0 9.6356
2.0000 0 9.6356
2.0000 1 7
1.0000 1 5
3.0000 1 6
1.0000 1 10
3.0000 1 44
2.0000 1 12
Now, what I want is that find minimum value of third column for the first column with equal value in each loop of second column.
Maybe it is better to see the result what I mean.
2.0000 0 3.1971
1.0000 0 3.1971
3.0000 0 6.4662
2.0000 1 7
1.0000 1 5
3.0000 1 6
Really appreciate ahmad Mohammadihttps://www.mathworks.com/matlabcentral/profile/authors/14439906tag:www.mathworks.com,2005:Question/5776272020-08-10T12:55:55Z2020-08-10T22:18:13ZUsage of structure as input of a function. Is it efficient ? Hello Mathworks community,
I have a general questioning about the efficiency / relevance of using structures as function inputs. I'll try to be clear...
I'm working on a code that has around 300 variables. I find very convenient to gather / sort these variables as fields of a few (~5) structures to sort them by "type". That clears my workspace and allow me to make shorter function calls. For example, I have a structure Model that contains fields .param1 .param2 ... param40 (all different, can be scalars, small vectors or small 3D matrices).
So, when I want to make some computation, I just do :
[output] = some_function(Model, other_input) ;
Furthermore, I use in my code a lot of functions / sub-functions / sub-sub-functions... I know that this might not be the most relevant in MatLab, but I think I have a good reason to do so. First that simplifies the structure of my code since I have a lot of sequential actions, so having small divided tasks is way more easy to manage. And secondly I intend to translate the code in C using MatLab Coder to run on an embedded platform.
That scheme was fine for me, until I started working on optimization / computing time and realized that there was a big difference between the 2 solutions below:
function [output] = some_function(Model, other_input)
% [...]
% Solution 1
% (tic)
% (for i = 1:1e6)
output = some_sub_function(Model.param1, Model.param2, Model.param3, other_input) ;
% (end)
% (toc) ==> ~4 seconds
% Solution 2
P1 = Model.param1 ;
P2 = Model.param2 ;
P3 = Model.param3 ;
% (tic)
% (for i = 1:1e6)
output = some_sub_function(P1, P2, P3, other_input) ;
% (end)
% (toc) ==> ~0.4 seconds, 10 times faster !
% [...]
end
Since computing time is critical for my work, I start to doubt about the choices I made. The thing is that if I stop using structures, I'll have gigantic function calls to write. And if I stop using functions, I'll have a gigantic code to naviguate into...
I've struggled to find ressources online about that matter (maybe I didn't find the right keywords), so I am curious about advices or feedback you could have ?
Thanks !Antoine Laurinhttps://www.mathworks.com/matlabcentral/profile/authors/15880444tag:www.mathworks.com,2005:Question/5774232020-08-10T03:53:54Z2020-08-10T22:17:12ZFitting weird curve into exponential functionsHello,
I have the following curve.
I want to fit it into a closed-form equation. I tried to use GRABIT to get a vector of values that could plot it.
x = [0.0194119350975558 0.248031785422458 0.291351961297183 0.334455968629621 0.397706884103397 0.439513880182100 0.459876956865727 0.644744294231326 0.658622314646282 0.755249653049490 0.832378588938224 0.889360616685617 0.929005927341429 0.970164417793265 0.990095157392316 1.05248139869694 1.11508380854384 1.20042714903956 1.24439583054116 1.26670442410539 1.33211702500205 1.40033981694848 1.46964345160635 1.56039100565929 1.58464511610412 1.60738604675293 1.67279864764960 1.73734657437711 1.84391766572561 1.92839633205217 1.99143107898366 2.07482890259878 2.26069061525890 2.34387227033173 2.42813476811600 2.53492202800680 2.62113004267167 2.70712188879425 2.73029515652764 2.81693550827709 2.88234810917376 2.98956770614913 3.07491104664485 3.18169830653564 3.28783706079956 3.47910298701692 9.89096458726940]
y = [0.382895015585752 0.936494005646322 0.944570062386241 0.950609811457797 0.946433435220773 0.940255338282152 0.932075520641934 0.473525838625860 0.404256790934756 0.314486318692959 0.241040894764830 0.177811596145283 0.151270422523033 0.138983402579323 0.126730969602380 0.114409362691904 0.104124063449791 0.108058330919451 0.122243310664459 0.132390262039507 0.148576962486111 0.191235662621433 0.244075901098568 0.298917860277301 0.327391580667615 0.341611147379389 0.357797847825993 0.365839317599146 0.369738998102040 0.365528034898250 0.359315350992862 0.344922849447257 0.295740182705652 0.279311373491684 0.273064102619530 0.279000090790788 0.291079588933900 0.301122779408649 0.319414961457149 0.335567074936987 0.351753775383591 0.361762378891574 0.365696646361235 0.371632634532492 0.371459699698661 0.373184724666128 0.372920999044535]
However, I am trying to fit that into an equation, whatever it is. Is that possible? If so, how can I do that
Thanks,Romiohttps://www.mathworks.com/matlabcentral/profile/authors/10838202tag:www.mathworks.com,2005:Question/5744832020-08-03T14:52:13Z2020-08-10T22:09:25ZGreek character in script turned to a square or a question mark - any ideas why?I copied a script from an older computer with Matlab 2012b to a new computer with Matlab 2017a and when I opened it, a Greek character 'μ' was encoded as a little square (maybe missing font). After Installing the Greek language option in MS Windows and typing in its place the letter μ, running the script reported an error (wrong matrix dimensions). So I reloaded the saved script and the character μ had now been replaced by a questionmark. Does anyone know what is going on? I have not witnessed this before. The faulty character encoding may have nothing to do with Matlab itself.Nick Aggelopouloshttps://www.mathworks.com/matlabcentral/profile/authors/18946353tag:www.mathworks.com,2005:Question/5778462020-08-10T20:22:58Z2020-08-10T22:05:20ZMatlab solve cannot find explicit solutionsfor symbolic equation.I have a system of 12 equations, and I want to find the fixed point when all equations = 0. Here is my code:
clear x1 x2 x3 x4 x5 x6 r1 r2 r3 r4 r5 r6 f1 f2 f3 f4 f5 f6 c p alpha beta b
syms x1 x2 x3 x4 x5 x6 r1 r2 r3 r4 r5 r6 f1 f2 f3 f4 f5 f6 c p alpha beta b %all symbols
%now define the ODEs
x1dot = f1*x1 - p*x1*(r1 + beta*r2 + beta*r4);
x2dot = f2*x2 - p*x2*(r2);
x3dot = f3*x3 - p*x3*(r3 + beta*r2);
x4dot = f4*x4 - p*x4*(beta*r1 + r4 + beta*r5);
x5dot = f5*x5 - p*x5*(r5);
x6dot = f6*x6 - p*x6*(beta*r5 + r6);
r1dot = c*((x1*r1/(r1+alpha*r2+alpha*r4)) + (alpha*x4*r1/(r4+alpha*r1+alpha*r5))) - b*r1;
r2dot = c*((alpha*x1*r2/(r1+alpha*r2+alpha*r4)) + x2 + (alpha*x3*r2/(r3+alpha*r2))) - b*r2;
r3dot = c*((x3*r3/(alpha*r2+r3))) - b*r3;
r4dot = c*((alpha*x1*r4/(r1+alpha*r2+alpha*r4)) + (x4*r4/(r4+alpha*r1+alpha*r5))) - b*r4;
r5dot = c*((alpha*x4*r5/(r4+alpha*r1+alpha*r5)) + x5 + (alpha*x6*r5/(alpha*r5+r6))) - b*r5;
r6dot = c*(x6*r6/(alpha*r5+r6)) - b*r6;
%define system of ODEs as the function
fun = [x1dot, x2dot, x3dot, x4dot, x5dot, x6dot, r1dot, r2dot, r3dot, r4dot, r5dot, r6dot];
%To compute the fixed points, solve function == 0
S = solve(x1dot == 0, x2dot == 0, x3dot == 0, x4dot == 0, x5dot == 0, x6dot == 0, r1dot == 0, r2dot == 0, r3dot == 0, r4dot == 0, r5dot == 0, r6dot == 0, [x1 x2 x3 x4 x5 x6 r1 r2 r3 r4 r5 r6]);
I can find the solutions by hand. Also, I have used the same code to find fixed points of similar system of equations, so I'm not sure what's wrong. Can someone please help me figure out what's wrong here?
Interestingly, this code works for the following system of equations:
x1dot = f1*x1 - p*x1*(r1 + beta*r2 + beta*r5);
x2dot = f2*x2 - p*x2*(r2);
x3dot = f3*x3 - p*x3*(r3 + beta*r2);
x4dot = f4*x4 - p*x4*(beta*r2 + r4 + beta*r5);
x5dot = f5*x5 - p*x5*(r5);
x6dot = f6*x6 - p*x6*(beta*r5 + r6);
r1dot = c*(x1*r1/(r1+alpha*r2+alpha*r5)) - b*r1;
r2dot = c*((alpha*x1*r2/(r1+alpha*r2+alpha*r5)) + x2 + (alpha*x3*r2/(r3+alpha*r2)) + (alpha*x4*r2/(alpha*r2+r4+alpha*r5))) - b*r2;
r3dot = c*((x3*r3/(alpha*r2+r3))) - b*r3;
r4dot = c*(x4*r4/(r4+alpha*r2+alpha*r5)) - b*r4;
r5dot = c*((alpha*x1*r5/(r1+alpha*r2+alpha*r5)) + (alpha*x4*r5/(alpha*r2+r4+alpha*r5)) + x5 + (alpha*x6*r5/(alpha*r5+r6))) - b*r5;
r6dot = c*(x6*r6/(alpha*r5+r6)) - b*r6;
which is very similar, and has the same number of variables. In fact this code gives me more than 100 solutions and the conidtions associated with them.
Thank you!Athulya Ram Sreedharan Nairhttps://www.mathworks.com/matlabcentral/profile/authors/12527625tag:www.mathworks.com,2005:Question/5772702020-08-09T15:56:34Z2020-08-10T21:55:17ZPlotting fits over significantly larger axis rangesHello,
I am encountering a strange behaviour of matlab, and couldn't find a way to force Matlab to do so.
Both graphs are fitting the excactly same fit, which i am polling from a structure.
The only difference is that for the graphs that look weird, I am plotting them over the axis [-2000 2000 -800 800], and then scale the figure back down to the actual xy-limits of the plotted data + margin on all sites [1 3 0.3 1.2]. The picture above is zoomed out a bit to see that the graphs are plotted outside the axis that I plotted the "finer" graphs over.
My current idea is that matlab obviously optimises the weird graphs shown above to look right on the axes you define:
Sadly, that would suggest that there is no way of optimise the plot over larger distances, and that I will have to adjust the factor for the first sketch down a lot, to get it to look properly again.
Or is there a method to force matlab to not simplify?
Thank you & stay healty.
Claudius AppelClaudius Simon Appelhttps://www.mathworks.com/matlabcentral/profile/authors/16470428tag:www.mathworks.com,2005:Question/3072122016-10-13T23:35:18Z2020-08-10T21:51:03ZCascade-forward neural network adding new unitsFor Cascade correlation network I found this definition: _We add hidden units to the network one by one. Each new unit therefore adds a new one-unit "layer" to the network, unless some of its incoming weights happen to be zero_. This is confuse me beacuse when I run Cascade network in MATLAB it looks like there is 10 neurons from beggining for example and I am not sure if it's the maximum of neurons only and it's really adding one by one during learning or there is 10 fixed neurons from beggining. How it works? Thank you.EdWoodhttps://www.mathworks.com/matlabcentral/profile/authors/7976091tag:www.mathworks.com,2005:Question/5772222020-08-09T13:15:22Z2020-08-10T21:48:41ZHow To Create A Persistence PlotI have quite a large data set that I want to visulaise by overlaying all the traces on one plot, with the traces only using one colour & the opacity/brightness of the resulting trace determined by how many instances of a particular value occur at each point - the only thing I can think to compare it to would be persistence on an old school oscilloscope.
Can someone point me to the correct plot type to achieve this or help me out with some code?
ThanksDrEamonnhttps://www.mathworks.com/matlabcentral/profile/authors/14791607tag:www.mathworks.com,2005:Question/5778612020-08-10T21:39:47Z2020-08-10T21:39:47ZDetermine if MATLAB Command Window is open in C# late bindingI am using late binding in C# to work with the MATLAB COM Automation Server. I am using this code to create the instance:
Type matlab = Type.GetTypeFromProgID("Matlab.Autoserver");
object instance = Activator.CreateInstance(matlab);
After creating the instance, a MATLAB Command Window opens up. Since it is possible for users to manually close that window before the code calls Quit, I am trying to find a way to check whether or not the command window is still open. Is there a way to do this other than just looking for errors?Nolin Borrero Jrhttps://www.mathworks.com/matlabcentral/profile/authors/19136961tag:www.mathworks.com,2005:Question/5777532020-08-10T15:37:37Z2020-08-10T21:36:23Zhow to detemine this residual matrix ?I calculate the cumulative sum of a matrix :Gm,n(i,j)
Now, the next step is '' we adopt the simplest function of a plane-fitting (i.e.Gm,n(i,j)=ai+bj+c ) to fit the trending for each surface Gm,n and determine the residual matrix ym,n(i,j).''
Please, can someone give me the code how to detemine this residual matrix, please ?Ker Nadhttps://www.mathworks.com/matlabcentral/profile/authors/7154953tag:www.mathworks.com,2005:Question/5756592020-08-05T16:28:30Z2020-08-10T21:30:20Zcovert true colour image to grayI have an image 768X1024X3 true colour in bmp, how do I convert to gray 768X1024 only. I used rgb2gray which converts to gray but still 768X1024X3, But it has to just 768X1024, because i need to further process the image, Rakesh Vhttps://www.mathworks.com/matlabcentral/profile/authors/15608549tag:www.mathworks.com,2005:Question/4457042019-02-19T02:24:55Z2020-08-10T21:25:17ZHow do I fix my error in line 6?Download the code sumOfIntegers.m, we can measure how long the function takes to execute for various values of N. We will focus on the main loop in the function. We can add a tic/toc pair around the loop so it becomes:
%...
tic
for j = 1 : N
total = total + a(j); end
toc %.
..
Save the code, and run the function with values of N one thousand and one million. Report and compare the time used to execute the function.
function sumOfIntegers(N)
% Usage: sumOfIntegers(N)
% Add up all the integers from 1 up to N and report
% the result.
n=input('final number:')
a = 1:N
total = 0;
for j = 1:N
total = total + a(j);
end
% ...
tic
for j=1:N
total=total+a(j);
end
toc
% ...
fprintf('Sum of first %u integers = %u \n', N, total);
When i go to run this code, i keep getting an error in line 6 saying i don't have enough input values. I'm not sure how to fix that.Abigail McGaheyhttps://www.mathworks.com/matlabcentral/profile/authors/14493156tag:www.mathworks.com,2005:Question/5775102020-08-10T08:32:11Z2020-08-10T21:23:10Zhow to create a matrix in a for-loopHello all.
I have 20 participants. After processing their data, I got a table of 1* a number ranging from ... to ... , for each. The unumber of columns is the same number of elecrodes in an EEG file. How can I make one matrix for all participants and then wirte all the data in one excel file (one excel file with the same number of rows as the number of particiopants)? I have written the following. the size of the "outputtable" is different for each person, ranging from ... to 62. Is it possible to write each number under the same "chLabels"?
I thank you in advance.
output_20_participants=[ ] ;
for i=1:20
fileName= soemthing
if exist (fileName)
do this
% Prepare output table
outputTable = array2table(ERP, 'VariableNames', chLabels, 'RowNames', strcat('S',convertCharsToStrings(num2str(i)))); % "ouputTable" is 1*65 table
???
end
end
writetable( output_20_participants, 'test.xlsx','WriteVariableNames', true, 'WriteRowNames', true); %I do not understand the use of "true".!!!Elahehhttps://www.mathworks.com/matlabcentral/profile/authors/12476322tag:www.mathworks.com,2005:Question/5751522020-08-04T18:40:24Z2020-08-10T21:20:08ZI need help solving a system of differential equations. The equations are given below, in matrix form. The problem that I'm having is regarding the fact that I have time dependant elements in the matrices.Jelena Kresojahttps://www.mathworks.com/matlabcentral/profile/authors/12912861tag:www.mathworks.com,2005:Question/4801122019-09-12T04:00:00Z2020-08-10T21:17:09ZWhy do I get a "java.lang.OutOfMemoryError" or "there is insufficient memory for the Java Runtime Environment to continue" when deploying a silent install using SCCM on a Windows 10 machine?When deploying a silent installation of MATLAB using SCCM (ConfigMgr) on a Windows 10 machine, why do I get the following text:
java.lang.OutOfMemoryError
or
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (malloc) failed to allocate 33952 bytes for Chunk::new
# Possible reasons:
# The system is out of physical RAM or swap space
# In 32 bit mode, the process size limit was hit
# Possible solutions:
# Reduce memory load on the system
# Increase physical memory or swap space
# Check if swap backing store is full
# Use 64 bit Java on a 64 bit OS
# Decrease Java heap size (-Xmx/-Xms)
# Decrease number of Java threads
# Decrease Java thread stack sizes (-Xss)
# Set larger code cache with -XX:ReservedCodeCacheSize=
# This output file may be truncated or incomplete.
#
# Out of Memory Error (allocation.cpp:390), pid=9848, tid=0x0000000000002d2c
#
# JRE version: Java(TM) SE Runtime Environment (8.0_181-b13) (build 1.8.0_181-b13)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.181-b13 mixed mode windows-amd64 compressed oops)
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
MathWorks Support Teamhttps://www.mathworks.com/matlabcentral/profile/authors/4622813tag:www.mathworks.com,2005:Question/5778552020-08-10T21:17:05Z2020-08-10T21:17:05ZImage processing using MatlabHello,
I have one landscape panorama image. First, I have to convert into balck and white image. then, i have to distinguish image as for buildings(object) = 1 and for sky= 0
then i have to convert that image into excel file.
how can i do that?
here, I am just looking for flow or approach.
thanks in advance!KAPIL JADHAVhttps://www.mathworks.com/matlabcentral/profile/authors/16795996tag:www.mathworks.com,2005:Question/5726262020-07-30T04:16:15Z2020-08-10T21:12:30Zcalculating error while averaging multiple imagesHi, I have a simple problem and needs guidance. I have 15 image files. I want to calculate the average of these images and calculate error on these images. Any help is appreciated.Sumera Yaminhttps://www.mathworks.com/matlabcentral/profile/authors/5464714tag:www.mathworks.com,2005:Question/5773752020-08-09T23:36:44Z2020-08-10T21:09:55ZReading a hex table with some undefined values I have a text table with hex values. Some of the values are of the form 0xXXXX. I'd like to read in the entire table as doubles with the 0xXXXX entries read as NaN. How do I do that?Roberthttps://www.mathworks.com/matlabcentral/profile/authors/172806tag:www.mathworks.com,2005:Question/5767332020-08-07T21:26:14Z2020-08-10T20:58:20ZI need to find the angle from horizontal that tangents to a curve make for multiple pointsHi All,
I have [x,y] coordinates that form a convex shape, I need to find the tangent and subsequently the angle from horizontal that each tangent makes at each [x,y] coordinate.
I have used two different approaches so far but I have struggled with both. Firstly, I attempted to use polyfit to create an equation from the points, then polyder to find the derivative and finally polyval to find the gradients at each point. I got really small values for the gradient that don't make sense to me.
Secondly, I am attempting to use a system whereby I find the slope with s(i) = ( y(i+1)-y(i-1) ) / ( x(i+1) - x(i-1) ). Then I need to find the expression for the line. I am struggling with how to set up a for loop where I can select the +1 and -1 values of x and y within the same loop and how to create an equation for the line.
The 2nd image that I have attached explains exactly what I am trying to acheive.
Can anyone help me out?
global rmax deltar npi npj th gamma Ma T_inf V_inf cp_air rho_air R_air
rmax = rmax + deltar;
x = rmax.*cos(th);
y = rmax.*sin(th);
coord = [x, y];
p = polyfit(x,y,2);
d = polyder(p);
val = polyval(d, x);
Laurence Maskellhttps://www.mathworks.com/matlabcentral/profile/authors/16514336tag:www.mathworks.com,2005:Question/1004962013-06-14T14:59:00Z2020-08-10T20:58:17ZWhy do I receive License Manager Error -8?Why do I receive "License Manager Error -8"?
License Manager Error -8.
License checkout failed. Encryption code in license file is inconsistent.
MathWorks Support Teamhttps://www.mathworks.com/matlabcentral/profile/authors/4622813tag:www.mathworks.com,2005:Question/5778432020-08-10T19:58:50Z2020-08-10T20:51:11ZPlease help me understand whether I have set up a loop and performed an RMSE (Root Mean Square Error) calculation correctlyI am returning to Matlab after such a long break that I'm essentially a newbie. I'd be very grateful if someone would please help me figure out if I have done what I intend to do!
I have a column of data (avgW) from measuring something over time.
I have an equation (second line of my code below) to calculate the same thing I measured (wCalc). In the equation, the parameters, a, b, c, d, e, and f are all constants. The parameter "columnOfData" is a column of distinct values.
My goal is to find the value of "x" in the equation. What I am trying to do below is first plug in a test value for x (1 - 10000). Then figure out which value (between 1 and 10000) gives me the smallest difference between wCalc and avgW.
I think my method so far would work if "columnOfData" were a constant, but it isn't and I am lost. I'm not even sure what I'm going to end up with when my current calculation finishes. Would anyone happen to know how to find and plot and record the lowest value of RMSE for each value of the column/vector, columnOfData?
Please feel free to comment if there are more appropriate tags for this question. Thank you.
for x = [1:1:10000]
wCalc = ( ( a ./ ( ( columnOfData ./ x ) - b ) ) - c - d - e ) .* f;
RMSE(x) = sqrt( sum( ( wCalc - avgW).^2) ./ g );
endAnn Sthttps://www.mathworks.com/matlabcentral/profile/authors/2276473tag:www.mathworks.com,2005:Question/5778522020-08-10T20:51:04Z2020-08-10T20:51:04ZParameters of multivariate multinomial distribution using Naive Bayes classifierDue to having categorical feature, I fitted multivariate multinomial distribution to a Naive Bayes classifier. I can not find the parameters of the fitting in the resultd model. I mean something analogousr to mean and standard deviation when having normal distribution. I want to visualize the distribution fitted in my model.
Zeynab Mousavikhamenehttps://www.mathworks.com/matlabcentral/profile/authors/14179884tag:www.mathworks.com,2005:Question/5774052020-08-10T03:12:35Z2020-08-10T20:46:29ZRounded random numbers with fixed sumI'm trying to generate a 1xK array with 'random' numbers that sum to 1, but that are also rounded to either 1 or 2 decimal places.
For example, if K=3, and I want the numbers to 2 decimal places, this is what I would expect:
array = [0.27, 0.45, 0.27].
So far I am unable to achieve this. Here is my code.
K = 3;
r = rand(1,K);
r = round(r/sum(r),2);
Without rounding the numbers sum to 1, but once rounded the numbers only to sum to 1 approximately 50% of the time.
Any help would be greatly appreciated, thanks!Thomas Coppinhttps://www.mathworks.com/matlabcentral/profile/authors/5131696tag:www.mathworks.com,2005:Question/925662013-07-19T18:07:00Z2020-08-10T20:43:00ZWhy does MATLAB get stuck in the "Initializing" or "Busy" state or take a long time to start?MATLAB opens but the status states 'Initializing' or 'Busy' for a long time. MATLAB takes a long time to launch with or without a remote license manager.
MathWorks Support Teamhttps://www.mathworks.com/matlabcentral/profile/authors/4622813tag:www.mathworks.com,2005:Question/2237612015-06-14T12:33:06Z2020-08-10T20:34:33Zhow to find the element which is greater than or equal to its row and smaller or equal to its column in a matrixHi everyone;
I am going to find the saddle points of a matrix M. The question is given below...
Write a function called saddle that finds saddle points in the input matrix M. For the purposes of this problem, a saddle point is defined as an element whose value is greater than or equal to every element in its row, and less than or equal to every element in its column. Note that there may be more than one saddle point in M. Return a matrix indices that has exactly two columns. Each row of indices corresponds to one saddle point with the first element of the row containing the row index of the saddle point and the second column containing the column index. The saddle points are provided in indices in the same order they are located in M according to column-major ordering. If there is no saddle point in M, then indices is the empty array.
I am trying that code:
function indices = saddle(M)
[ rows,cols ] = size(M);
[valR,posR] = max(M,[],2);
[valC,posC] = min(M,[],1);
indices= [];
for i = 1:length(posR)
if i == posC(posR(i))
indices= [indices; i, posR(i)];
end
end
end
It is running fine. But when i test my code for
>> mat=zeros(5,3)
mat =
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
I am getting wrong output :
saddle(mat)
ans =
1 1
the correct output must be
saddle(mat)
ans =
1 1
2 1
3 1
4 1
5 1
1 2
2 2
3 2
4 2
5 2
1 3
2 3
3 3
4 3
5 3
What i am doing wrong?? Thanks in advanceMuhammad Usman Saleemhttps://www.mathworks.com/matlabcentral/profile/authors/6394611tag:www.mathworks.com,2005:Question/5727012020-07-30T07:45:24Z2020-08-10T20:34:32ZSimple circuit using SimulinkI would like to implement simple circuits that I am studying during the electrical engineering (mechanical engineering) course. Can anyone tell me how the following circuit should be drawn in simulink? (R2020a)
or
Lucahttps://www.mathworks.com/matlabcentral/profile/authors/10060977tag:www.mathworks.com,2005:Question/5778282020-08-10T18:43:48Z2020-08-10T20:26:23ZHow to loop time ( hours and minutes ) in a data setHi all,
I am working with a 264,xxx *12 dataset, I imported them to matlab as column vectors due to the nature of the sampling the intervals range from 5 to 30 seconds in a 4 hour span for example 6 to 10 pm. I want to achive two things A) be able to average the observations to the minute, b) be able to do a time series graph between y1...y4 vs x(time). My question is where I can find information to do this on matlab?
Thanks in advancedesert_scientist90https://www.mathworks.com/matlabcentral/profile/authors/15423469tag:www.mathworks.com,2005:Question/5554632020-06-26T20:24:15Z2020-08-10T20:25:22ZHow to fitline on my binary image and find distanceHello,
I have a question about my image processing problem. I have convert the image into binary and now i would like to use fitline on my image. Basically want to smooth the line with the curve. I am a beginner for MATLAB software. Please help me to find the solution. Also i want to find distance of one thin line to thick line (top to bottom).
I am attachng my picture as png. Also my code is there.Prashanthttps://www.mathworks.com/matlabcentral/profile/authors/12182670tag:www.mathworks.com,2005:Question/4664202019-06-10T22:58:32Z2020-08-10T20:17:20ZHow to Extract data from 3D implicit plot?I would like to extract x, y and z data coordinates from this function.
My plot:
f_gy = @(x,y,z) sin(x).*cos(y) + sin(y).*cos(z) + sin(z).*cos(x);
x_gy_l = 0*pi;
x_gy_u = 6*pi;
y_gy_l = 0*pi;
y_gy_u = 6*pi;
z_gy_l = 0*pi;
z_gy_u = 6*pi;
% Mesh Density
MD_gy = 50;
% Face Color
C_gy = 'red';
p = fimplicit3(f_gy, [x_gy_l x_gy_u y_gy_l y_gy_u z_gy_l z_gy_u], 'meshdensity', MD_gy, 'facecolor', C_gy);
How can I get the data in the workspace as an array?
ThanksAravind Kanna Kundumani Janarthananhttps://www.mathworks.com/matlabcentral/profile/authors/14843530tag:www.mathworks.com,2005:Question/5777742020-08-10T16:43:47Z2020-08-10T20:14:20ZSmoothing curve with duplicate values using pchip I have been using pchip interpolation to smooth curves plotted from data points. This has worked fine except I can't figure out how to smooth the curve when there are duplicate x values. This is what I have now:
Pressure27 = TC27Data.Pressurepsi;
Efficiency27 = TC27Data.Efficiency;
[xUnique, ia, ic] = unique(Pressure27);
yMeans = accumarray(ic, Efficiency27, [], @mean);
xq27 = [1500:.001:1250];
yqp27 = pchip(xUnique,yMeans,xq27);
plot(xUnique,yMeans,'linewidth',2);
This is mostly not my original code, I found it on this forum here.
This successfuly plots the averaged data point where there were duplicate values, however the curve that plots is not as smooth as I would like it, I want to get rid of the linear jagged edges. How can I use pchip here to smooth the curve? Thanks!Rosemary A. Loerhttps://www.mathworks.com/matlabcentral/profile/authors/17300341tag:www.mathworks.com,2005:Question/4553952019-04-09T21:41:11Z2020-08-10T20:12:12Znext prime number using While loopsWe have to write a function called next_prime that takes a scalar positive integer input n. Use a while-loop to find and return k, the smallest prime number that is greater than n. we may use isprime function. plz help..Xenium Adilhttps://www.mathworks.com/matlabcentral/profile/authors/15258520tag:www.mathworks.com,2005:Question/5776632020-08-10T13:44:03Z2020-08-10T20:07:40Zscroll programmatically within uitableI am starting to build an app suing the AppDesigner and need to deal with a fairly large uitable (>1000 rows).
In some cases it would be nice to scroll within this table to a certain row or cell programmatically.
https://ch.mathworks.com/help/matlab/ref/matlab.ui.container.tree.scroll.html shows that in 2020a there is now the function scroll, which allows scrolling e.g. within a list box to a certain item.
Is there a way to do the same within a uitable (created using the AppDesigner)? If not, if there a plan to add this in the near future?
Steven Brossihttps://www.mathworks.com/matlabcentral/profile/authors/1423289tag:www.mathworks.com,2005:Question/5777382020-08-10T15:09:44Z2020-08-10T20:06:17Zpopulate a listbox with selected folder doc file names - App designerHow can I populate a listbox with all doc files in a selected folder using a button in App designer?
function selectDocButtonPushed(app, event)
app.selectedPath = uigetdir();
docFileInfo = dir('*.doc')
app.docListBox.Items = docFileInfo.name
endEly Razhttps://www.mathworks.com/matlabcentral/profile/authors/4267611