https://ww2.mathworks.cn/matlabcentral/answers/questionsMATLAB Answers — New Questions2020-09-18T21:16:35Ztag:ww2.mathworks.cn,2005:Question/5189502020-04-18T19:19:27Z2020-09-18T21:16:35ZChanging image rendering?Hey All,
attempting to visualize a raster of lines and running into issues. When the lines are plotted as lines, the image appears correctly, as follows:
When attempting to visualize the same lines (ignoring the large vertical and horizontal lines), I get the following
zooming in, all the same lines are present, just zoomed out they have varying degrees of visibility. Is there a way to modify MATLAB handling of this image to produce an image closer to what appears above?aboharbfhttps://ww2.mathworks.cn/matlabcentral/profile/authors/9244971tag:ww2.mathworks.cn,2005:Question/5960982020-09-18T15:54:25Z2020-09-18T21:16:32ZSeries of Matrix Equations SolutionI want to use MATLAB to solve a system of matrix equations as shown below (as an example): (A,B and C are unknown matrices)
What would be the best to do this?
Thanks,anurag bhattacharyyahttps://ww2.mathworks.cn/matlabcentral/profile/authors/9370892tag:ww2.mathworks.cn,2005:Question/5962122020-09-18T21:12:13Z2020-09-18T21:15:00Zglmfit not working: US's chances of recessionclose all
A=[ind us2y10 rec];
X=[ind us2y10];
[logitCoef] = glmfit(X,rec,'binomial','link','logit');
yfit=[ones(359,1) X]*logitCoef;
plot(yfit);
Hello everyone!
I'm trying to estimate a logit model for the probability of recession in the US, based on a constante factor, the inddustrial production and US yield curve slope for 2y and 10y. The results are not the one supposed to be, since the model is presenting out of bounds ([0,1]) estimates.
Thanks in advance for your time in checking the script.
Cheers,
PedroPedro Pereirahttps://ww2.mathworks.cn/matlabcentral/profile/authors/14568514tag:ww2.mathworks.cn,2005:Question/5924202020-09-12T00:15:46Z2020-09-18T21:14:26ZRemove Dashed Grey Asymptote Lines From PlotI have a plot of a few symbolic functions in matlab, and I'm getting some grey dashed lines. I'm going to guess that these are for asymptotes, which I expected. Is there a way to remove these lines?
Attached is my plot. The lines I'm talking about are at x = 4 and x = 0. Ignore the legend and other colors, that's another story.Benjamin Bloodhttps://ww2.mathworks.cn/matlabcentral/profile/authors/13538477tag:ww2.mathworks.cn,2005:Question/5962092020-09-18T21:03:02Z2020-09-18T21:14:12ZHow to Import/parse sparse data from a text file into MATLAB? I've been having issues with parsing data into MATLAB from a text file. The textfile has discontinuities between its strings (it has spaces), and it seems like everytime I tried to import the data into matlab it just combines everything and messes up the data. I would like to basically read the text file (attached) and import the corresponging strings with their values into an array (probably).
I also tried to import the file into Excel and see if I could delimiter my data in a nicer format so I can easily import it into MATLAB but excel also does not like the data format and it breaks every word into a column which messes up everything as well.
Any help would be greatly appreciate it.
Here is what I did so far:
%% Setup the Import Options and import the data
opts = delimitedTextImportOptions("NumVariables", 3);
% Specify range and delimiter
opts.DataLines = [2, Inf];
opts.Delimiter = ",";
% Specify column names and types
opts.VariableNames = ["TITLE", "BEGININPUTDATAECHO", "VarName3"];
opts.VariableTypes = ["string", "string", "string"];
% Specify file level properties
opts.ExtraColumnsRule = "ignore";
opts.EmptyLineRule = "read";
% Specify variable properties
opts = setvaropts(opts, ["TITLE", "BEGININPUTDATAECHO", "VarName3"], "WhitespaceRule", "preserve");
opts = setvaropts(opts, ["TITLE", "BEGININPUTDATAECHO", "VarName3"], "EmptyFieldRule", "auto");
% Import the data
ATR42500zjf2 = readtable("file", opts);
%% Clear temporary variables
clear opts
Bonie10https://ww2.mathworks.cn/matlabcentral/profile/authors/7908085tag:ww2.mathworks.cn,2005:Question/5962152020-09-18T21:13:31Z2020-09-18T21:13:31ZHow do I run a function I downloaded?So I downloaded this script nsumk to do some cool partition of integers for me: https://www.mathworks.com/matlabcentral/fileexchange/28340-nsumk
When i open it in matlab it appears in the editor window, I think it's like in the place where I would normally write scripts (once I get that advanced, haha!). Anyway, what do I have to do from here to get this functiln nsumk running in my command line?? I've tried typing in numk and stuff like that but can't get it to work.
If you can't tell, i'm a total scrub at this stuff, but i'm very interested!!
Simple explanations appreciated!! Peace out!!!!Michael Vaughanhttps://ww2.mathworks.cn/matlabcentral/profile/authors/13643439tag:ww2.mathworks.cn,2005:Question/5931432020-09-14T02:12:08Z2020-09-18T21:09:34ZSelecting n random elements within a for loopHi everyone,
So assume I have a dataset with 10 folders (each folder corresponding to a category).
In my example :
ListOfAllCategories is a 1x10 cell containing the list of all categories
ImageListForEachCategory is a 10x1 map that returns all images belonging to a given category.
My goal is to (1) "extract" all images belonging to all 10 categories and (2) draw n random images from the whole pool (all categories combined). However, I am encountering problems at the very beginning of the code. I am doing the following (to begin with) :
for i=1:length(ListOfAllCategories)
A = ListOfAllCategories{i};
B = ImageListForEachCategory(A);
disp(B)
end
When I display "B", I get a list of all the images from all categories but the folder in the workspace contains only the images belonging to the first category. Should I use a second For Loop in that case? Also, is there a different way to directly draw n images from the whole pool?
Thank you very much.
Best regards.M Jhttps://ww2.mathworks.cn/matlabcentral/profile/authors/18378804tag:ww2.mathworks.cn,2005:Question/5951502020-09-17T04:37:39Z2020-09-18T21:01:59ZI can't save a PSAT fileHi,
When I try to save a model an error pops up "Too many output arguments." & I can't save the file anyway. Could you please suggest any workaround to fix this?
ThanksABU SADAT MOHAMMAD SAYEMhttps://ww2.mathworks.cn/matlabcentral/profile/authors/17706630tag:ww2.mathworks.cn,2005:Question/5962062020-09-18T20:48:15Z2020-09-18T21:00:36ZRemoving elements in one matrix with same position as those in another matrix in matlabI have two large matrices, matrix Z and matrix H, both 121x962. In matrix Z I removed values below a desired threshold and left NaN in place of those elements, so the size of the matrix did not change. In matrix H, I want to remove the values that are in the corresponding position as those labelled NaN in matrix Z.
For example, in matrix Z I have elements [1,2], [50,7], [40,32], [113,6] etc. labelled as NaN. I want to remove these same elements ([1,2], [50,7], [40,32], [113,6] etc.) from matrix H. Is there a way to specify that I want to remove all the elements labelled NaN in Z from matrix H without having to provide the exact coordinates I want to remove.AShttps://ww2.mathworks.cn/matlabcentral/profile/authors/19228832tag:ww2.mathworks.cn,2005:Question/5955012020-09-17T16:18:51Z2020-09-18T20:59:02ZWorking with complex numbers in the Symbolic Math Toolbox. Why does angle(A) returns atan2(sin(alpha),cos(alpha)) instead of just alpha?%% Complex number using TRIGONOMETRIC form
% Let's define A as a complex number in polar form, with magnitude M and angle alpha
M = sym('M',{'real','positive'}); % magnitude
alpha = sym('alpha','real'); % angle
assume(alpha>-pi & alpha<pi)
A = M*(cos(alpha) + i*sin(alpha)); % complex number in polar form
% Now, I would expect abs(A) to return M. It does not.
abs(A)
% But, using rewrite and combine, I can get the it to return M
combine(rewrite(abs(A), 'sqrt'), 'sincos')
% Similarly, I would expect the angle(A) to return alpha, but instead we get atan2(sin(alpha), cos(alpha)).
angle(A)
% I tried the simplify and rewrite function, but I could not get the angle(A) to return alpha. Is there a way around this?
Pablo Tacconihttps://ww2.mathworks.cn/matlabcentral/profile/authors/7088107tag:ww2.mathworks.cn,2005:Question/5961882020-09-18T19:50:36Z2020-09-18T20:58:40Zprogress bar does not change color (Load)Hi all,
so i wanna make a load progress bar for my app, (see joined picture). I found a code on matlab : https://www.mathworks.com/matlabcentral/discussions/highlights/132277-new-in-r2020a-app-button-animation-truecolor-images
Unfortunately, the blue color does not show. anyone can tell what i've done wrong please ? thank you
% Change button name to "Processing"
app.ProgressButton.Text = 'Processing...';
% Put text on top of icon
app.ProgressButton.IconAlignment = 'left';
% Create waitbar with same color as button
wbar = permute(repmat(app.ProgressButton.BackgroundColor,150,1,2),[1,3,2]);
% Black frame around waitbar
wbar([1,end],:,:) = 0;
wbar(:,[1,end],:) = 0;
% Load the empty waitbar to the button
app.ProgressButton.Icon = wbar;
% Loop through something and update waitbar
n = 10;
for i = 1:n
% Update image data (royalblue)
currentProg = min(round((size(wbar,2)-2)*(i/n)),size(wbar,2)-2);
app.ProgressButton.Icon(2:end-1, 2:currentProg+1, 1) = 0.25391;
app.ProgressButton.Icon(2:end-1, 2:currentProg+1, 2) = 0.41016;
app.ProgressButton.Icon(2:end-1, 2:currentProg+1, 3) = 0.87891;
% Pause to slow down animation
pause(1)
end
% remove waitbar
app.ProgressButton.Icon = '';
% Change button name
app.ProgressButton.Text = 'Done !';
Khalala Mamourihttps://ww2.mathworks.cn/matlabcentral/profile/authors/13668647tag:ww2.mathworks.cn,2005:Question/5961972020-09-18T20:29:15Z2020-09-18T20:58:25ZHow can I get peaks values and distance between them indicated in the figure? How can I get only the three peaks values corresponding their x-axis values indicated in the figure? And the horizontal distance between peak1 and peak2 or between peak 1 and peak3. How can I also get the FWHM of the maximum peak (here peak1). I don't need other peaks values apart from these three.
Sohel Ranahttps://ww2.mathworks.cn/matlabcentral/profile/authors/13777906tag:ww2.mathworks.cn,2005:Question/2264372015-07-01T22:53:40Z2020-09-18T20:56:25ZObtain all integer partitions for a given integerIs there a way to compute all integer partitions for a given integer?
For example n=4
we have
4+ 0 + 0 +0
3+ 1 + 0 +0
2+ 2 + 0 +0
2+ 1 + 1 +0
1+ 1 + 1 +1
I would like to obtain a matrix
[4, 0, 0, 0;
3, 1, 0, 0;
2, 2, 0, 0;
2, 1, 1, 0;
1, 1, 1, 1] Farid Salazar Wonghttps://ww2.mathworks.cn/matlabcentral/profile/authors/3996652tag:ww2.mathworks.cn,2005:Question/3687252017-11-23T05:04:18Z2020-09-18T20:50:32ZMy matlab code for PV P&O tracking algorithm has an errorHello
I'm writing the code for P&O tracking as I want the output to be Power and Voltage where the max point is located.
From the figure, I expected the max power to be at 51.53 W at 16.32 V.
<</matlabcentral/answers/uploaded_files/95783/untitled2.jpg>>
But when I run the code, it always gives the result to the open-circuit voltage (last point of the curve) which is not correct, it gives me the result of 30.01 W at 19 V.
The code that I write is here, not sure I've done something wrong or not (I'm pretty new to matlab). The outputs are P and Vmpp
function [Vmpp,P] = PandO(V,I)
persistent Vold Pold Iold dV dI dP Power;
if isempty(Vold)
Vold =0; Iold = 0;
Pold = 0; dV = 0; dI = 0; dP = 0; Power = zeros(1000,1);
end
deltaV = 0.0001; % initialize
for i = 1:size(V,1)
Power(i) = V(i) .* I(i);
dV = V(i) - Vold;
dI = I(i) - Iold;
dP = Power(i) - Pold;
if dP ~= 0
if dP < 0
if dV <0
Vmpp = V(i) + deltaV;
else
Vmpp = V(i) - deltaV;
end
else
if dV < 0
Vmpp = V(i) - deltaV;
else
Vmpp = V(i) + deltaV;
end
end
else
Vmpp = V(i);
P = Power(i);
break
end
Vold = V(i);
Iold = I(i);
Pold = V(i).*I(i);
end
end
<</matlabcentral/answers/uploaded_files/95784/capture5.JPG>>
Any suggestion for me? thank you so much in advance
Jirada Gosumbonggothttps://ww2.mathworks.cn/matlabcentral/profile/authors/11253605tag:ww2.mathworks.cn,2005:Question/5957052020-09-18T02:13:32Z2020-09-18T20:46:47ZProblem allocating 24 workers using parpoolI am trying to execute a few jobs in parallel on a computing cluster. The maximum number of workers available per node is 24. When I execute the job, some jobs are allocated 24 workers, some are allocated 12, whereas some jobs are only running on one worker. What could possibly be the reason for this when the job script is the same for all jobs requesting for 24 workers per node? I looked at the job output for the job running on one worker and it says "
>> >> >> Starting parallel pool (parpool) using the 'local' profile ...
>> >> >> >> >> Starting parallel pool (parpool) using the 'local' profile ..."
This shows that the parpool did start for this job, however, only one worker was allocated. When I check the output of a job running on 24 workers, it says
">> >> >> Starting parallel pool (parpool) using the 'local' profile ...
Connected to the parallel pool (number of workers: 24)."
I am trying to run all jobs using all 24 workers for each job but I am not able to. Any help would be greatly appreciated.Geeta Garghttps://ww2.mathworks.cn/matlabcentral/profile/authors/8975685tag:ww2.mathworks.cn,2005:Question/5930472020-09-13T20:14:15Z2020-09-18T20:43:51Zmatrix manipulation and transposing so, I am writing this code to Create a table showing the maximum height for the following values of v and q: v = 10, 12, 14, 16, 18, 20 m/s q= 50, 60, 70, 80 The rows in the table should correspond to the speed values, and the column should correspond to the angles. where g=2.8. The formula for the question is v^2*sin(thetha)^2/2*g.
my question is why did i need to transpose v in my code so that it would work?
v=[2:2:20]
g=2.8
thetha=[50:10:80]
h=(v'.^2).*(sind(thetha).^2)./(2*g)
table=[0 thetha; v' h] armani canadyhttps://ww2.mathworks.cn/matlabcentral/profile/authors/17289794tag:ww2.mathworks.cn,2005:Question/5959902020-09-18T12:52:01Z2020-09-18T20:40:14Zhow to find roots of equationsHi. I want to extract roots(w) of below two equation(equations are detA and detB). The roots of equation are with respect to N(w(N)), i want to plot(N,w), how can i do this? thank you
syms w N
k1=70;
k2=200;
m1=0.1;
m2=0.064;
m3=0.04;
r=0.25
M1=(m2+m3)/m1;
M2=m2/m1;
K=k2/k1;
wn1=(sqrt(k1/m1))/(2*pi);
wn2=(sqrt(2*k2/m3))/(2*pi);
A=[-(1+M1)*(w/wn1)^2+2-2*cos(pi) -M2*(w/wn1)^2 -(M1-M2)*(w/wn1)^2;-(w/wn1)^2 -N*(w/wn1)^2+(2*K)/M2 -K/M2;-(w/wn2)^2 -0.5 1-(w/wn2)^2];
detA=det(A)
B=[-(1+M1)*(w/wn1)^2+2-2*cos(0) -M2*(w/wn1)^2 -(M1-M2)*(w/wn1)^2;-(w/wn1)^2 -N*(w/wn1)^2+(2*K)/M2 -K/M2;-(w/wn2)^2 -0.5 1-(w/wn2)^2];
detB=det(B)saman ahmadihttps://ww2.mathworks.cn/matlabcentral/profile/authors/18279448tag:ww2.mathworks.cn,2005:Question/5962032020-09-18T20:39:35Z2020-09-18T20:39:35ZHow to save each loop data?I am new to matlab so please bear with me. I am trying to show how y varies with the different u values. And im trying to to display that in a figure. But i dont seem get the saved data from the loop. Any suggestions?
c=3e8; %speed of light
u=0;
while u<(c)
y=1/(sqrt(1-((u^2)/(c^2))));
u=u+(0.01*c);
end
plot(u, y,'r')Abdirahman Mohamedhttps://ww2.mathworks.cn/matlabcentral/profile/authors/6905988tag:ww2.mathworks.cn,2005:Question/5961342020-09-18T17:25:05Z2020-09-18T20:34:09ZFormat a matrix with entries displayed as exact values I am trying to print a matrix with its entries displayed as exact values not fractional approximations. For example, the following code should print A exactly as it is initialized (not approximate sqrt(2) as 1393/985) but displays fractions. What format specification instead of rat should be used?
format rat
AB = [0 1 1; sqrt(2) 2 0; 0 1 1];
disp("AB: "); disp(AB) Aleem Andrewhttps://ww2.mathworks.cn/matlabcentral/profile/authors/13655223tag:ww2.mathworks.cn,2005:Question/5962002020-09-18T20:33:58Z2020-09-18T20:33:58ZStoring the generated matrices from a for loop into cell arrays and access them later to multiply them altogetherI have to write the corresponding MATLAB algorithm to get the first column of M = (A - x_k*I)(A - x_(k-1)*I)(A - x_1*I), where A is an nxn matrix, I is the identity matrix, and x is a vector of length k.
Here is my algorithm:
function [M] = double1(A, x)
k = length(x);
[n,n] = size(A);
for i = k:-1:1
M{i} = A-x(i)*eye(n);
end
I want to store the matrices that I get from my for loop into a cell array and access them later and multiply them altogether. How to do that? Any help, please?Pascale Bou Chahinehttps://ww2.mathworks.cn/matlabcentral/profile/authors/16075610tag:ww2.mathworks.cn,2005:Question/5961822020-09-18T19:40:54Z2020-09-18T20:25:14ZEven binned histogram to uneven bins?Hi all,
I have a csv file consisting of 256 bins each of 2mm width and I need to convert to uneven bins. 32 bins of 2mm width, 48 of 4mm width and 4 of 8mm depth. I would prefer not to use the bin edges as reference but rather the mid-point of the bins for reference but, if I need, I'll use the bin edges.
Can this be done using Matlab?
Apologies for not replying to my earlier posts.
Regards
TimTim Fulcherhttps://ww2.mathworks.cn/matlabcentral/profile/authors/4347519tag:ww2.mathworks.cn,2005:Question/5961672020-09-18T18:39:21Z2020-09-18T20:24:21ZExtract data from plotHello all
I have a plotted a graph with x=1 2 3 4 5 and y = 2 4 6 8 10.
Now I want to mark y= 6.5 on the plot. How to do it. I have asked this question in a simple way but the actual data I have is so big.
Hoping for suggestions
Thanking youVinay Srinivasanhttps://ww2.mathworks.cn/matlabcentral/profile/authors/16146690tag:ww2.mathworks.cn,2005:Question/5961702020-09-18T18:53:20Z2020-09-18T20:21:50ZHow can I create different colors in the plotted chart for a lot of dataHello everyone;
I have huge data set, and i plotted for at least 70 different sets. What should I do to color all lines differently? What are your suggestions?
I thank everyone in advanceAbidin Burak Nuzumlalihttps://ww2.mathworks.cn/matlabcentral/profile/authors/12362688tag:ww2.mathworks.cn,2005:Question/2221352015-06-02T20:35:48Z2020-09-18T20:18:57Zwhat function do i use to remove large object ?In matlab we use bwareaopen(I,n) function to remove object smaller than n pixel from image I.
Is there any function to remove object greater than m pixel from image I ?
what should i do to remove bigger object from image I?Priyanka Royhttps://ww2.mathworks.cn/matlabcentral/profile/authors/5567803tag:ww2.mathworks.cn,2005:Question/5961792020-09-18T19:30:43Z2020-09-18T20:11:13ZConvert data plot from Cartesian to spherical coordinates I have data plot shown below where the 'x' and 'y' coordiantes corresponds to the cartessian coordinates sin(theta) cos(phi) and sin(theta) sin(phi). I would like to obtain a plot where the 'x' and 'y' coordinates are theta and phi. Is there a command in Matlab that performs this coordinate transformation? theta and phi are the spherical coordinates.
Manushanker Balasubramanianhttps://ww2.mathworks.cn/matlabcentral/profile/authors/8342038tag:ww2.mathworks.cn,2005:Question/5961942020-09-18T19:59:54Z2020-09-18T20:10:40ZWhy won't this plot? %% Section 1: Initalization of Variables
%increments of x
x = -4:1:-1;
%
%The function we are given
y = x + (1 ./ (x.^2-1));
%% Section 2: Processing
plot(x,y)
axis([-15 15 0 15])
%I want to be able to see the y function appraching the verticle asymptote '-1' from the left but my function wont graphSerena Simpsonhttps://ww2.mathworks.cn/matlabcentral/profile/authors/19360621tag:ww2.mathworks.cn,2005:Question/5961912020-09-18T19:56:25Z2020-09-18T20:05:21ZError using 'pi' too many input errors with my equation%Defining given varibles
t = 0 :.1 :3;
f1 = 130;
f2 = 120;
y1 = cosd(2*pi*f1*t);
y2 = cosd(2*pi*f2*t);
%% Section 2: Processing
%equation given
y = 2 * cos(2*pi(f1+f2/2)*t) * cos(2*pi(f1-f2/2)*t);
%% Section 3: Result Output
plot(y)
title('Alternating Loud and Quiet Sounds')
xlabel('Time(s)')
ylabel('Amplitutde')Serena Simpsonhttps://ww2.mathworks.cn/matlabcentral/profile/authors/19360621tag:ww2.mathworks.cn,2005:Question/5959182020-09-18T10:46:17Z2020-09-18T20:02:20ZBuilding Low-pass filter with Sinc functionDear Community,
I am trying to build a low-pass filter by using a sinc function for my homework assignment. I then use convolution to later filter an audio sample with this filter. However, when I plot the filter in a bode plot it looks like a high-pass filter. Can anyone tell me what I'm doing wrong?
Thanks in advance!
%% Downsampled by K with low-pass filter
% Build filter
clear all; close all
K = 2;
fs = 1600;
N = 51;
n = (-(N-1)/2:1:(N-1)/2);
h = (1/K) * sinc((pi/K)*n);
% Plot frequency response filter
[H, H_vec] = fftFreq(h, fs, 1 );
figure
plot(H_vec*2*pi/fs, abs(H))
filt_tf =tf(h,1,1/fs,'Variable','z^-1');
figure
bode(filt_tf)
function [ X , f ] = fftFreq( data , fs, w )
% Number of FFT points
NFFT = length( data );
% calculate FFT
X = fft(data .* w);
% calculate frequency spacing
df = fs/NFFT;
% calculate unshifted frequency vector
f = (0:(NFFT-1)) * df;
end
Lianghttps://ww2.mathworks.cn/matlabcentral/profile/authors/16120207tag:ww2.mathworks.cn,2005:Question/4400632019-01-16T14:43:08Z2020-09-18T20:01:30ZUnknown 'internal.matlab.variableeditor.peer.WidgetRegistry' warning.Whenever I run my GUI application, the application opens, but this warning appears.
My GUI contains the following:
uifigure
uitable
uibutton
uieditfield
Also, I did not use appdeveloper to create this; everything was created in an m file.
Warning: A value of class "internal.matlab.variableeditor.peer.WidgetRegistry" was indexed with no subscripts specified. Currently the result of this
operation is the indexed value itself, but in a future release, it will be an error..
> In matlab.ui.internal.controller.uitable.VariableEditorArrayAdapter/getViewModel (line 85)
In internal.matlab.variableeditor.peer.PeerDocument (line 37)
In internal.matlab.variableeditor.peer.PeerManager/createDocument (line 400)
In internal.matlab.variableeditor.peer.PeerManager/doDelayedDocumentCreation (line 535)
In internal.matlab.variableeditor.peer.PeerManager/openvar (line 590)
In matlab.ui.internal.controller.uitable.VariableEditorView/createViewStrategy (line 61)
In matlab.ui.internal.controller.uitable.VariableEditorView (line 43)
In matlab.ui.internal.controller.uitable.WebTableController/createTableServer (line 391)
In matlab.ui.internal.controller.uitable.WebTableController/add (line 41)
In matlab.ui.internal.componentframework.WebControllerFactory/create (line 93)
In ProprietaryNamespace.ProprietaryConstructor (line 6)
For some reason, my stack jumps from my constructor into some internal component registry, so I don't know the exact line in my constructor where the issue appears. Because of this, I suspect that this is more a matlab bug than my own code, nonetheless I'd like to be able to get rid of it. Any advice?Jacob Hootmanhttps://ww2.mathworks.cn/matlabcentral/profile/authors/13262895tag:ww2.mathworks.cn,2005:Question/5961852020-09-18T19:49:25Z2020-09-18T19:52:57ZCan individual ColSep('solid') & RowSep('solid') be defined in mlreportgen.dom.(Formal)Table?From Matlab examples on mlreportgen.dom.Table and mlreportgen.dom.FormalTable, the border of cells are overall defined:
tableStyle = {Width('100%'), Border('solid'), ColSep('solid'), RowSep('solid')};
t = FormalTable(data);
t.Style = [t.Style tableStyle];
t.Body.TableEntriesStyle = [t.Body.TableEntriesStyle, bodyStyle];
and
formalTable = mlreportgen.dom.FormalTable(tbl_header,traffic_camera_data);
formalTable.RowSep = "Solid";
formalTable.ColSep = "Solid";
formalTable.Border = "Solid";
Can the border of each table cell be defined individually? For example, some cell with only the bottom border.
Thanks.Johnhttps://ww2.mathworks.cn/matlabcentral/profile/authors/15413829tag:ww2.mathworks.cn,2005:Question/5961462020-09-18T17:45:46Z2020-09-18T19:48:14Zhow to get character from an array using another logical array?how to get character from an array using another logical array?
for example
V = '1b.%291x g'
'yig&aaSgwa'
'tqtbbs!?R!'
logicalVec = [ 1 0 1 0 1 0 1 0 1 1; 0 1 1 0 1 0 0 0 1 1; 1 0 1 0 0 1 1 1 0 1]
Mithushan Kanthasamyhttps://ww2.mathworks.cn/matlabcentral/profile/authors/19237643tag:ww2.mathworks.cn,2005:Question/4150092018-08-15T17:02:47Z2020-09-18T19:46:45ZHow do i estimate of channel parameters of UWB by Saleh Valenzuela Model ?I have 2 datasets of UWB channel sounding. I can plot them in PDP vs time delay profile. But I need to get the similarity percentage or the parameters of the channel profiles by *Saleh Valenzuela Model*. I am not getting any idea how to do it. So, anyone please help me to get through this or at least tell me how can I proceed...
<</matlabcentral/answers/uploaded_files/129097/test.png>>
SOURAV PAULhttps://ww2.mathworks.cn/matlabcentral/profile/authors/9466039tag:ww2.mathworks.cn,2005:Question/5961102020-09-18T16:32:09Z2020-09-18T19:42:50ZHow do I troubleshoot if a plot line doesn't show up on a figureDue to the nature of the problem requiring a large sum of data, I can't provide an example code beyond this.
plot([0 7],[meet4060 meet4060],':k')
Where meet4060=55.
It worked in the original code I was working on and it worked in a separate figure on its own, but it is not showing up in the recent code. When this happens, what should I be looking for to begin solving the trouble?
Oscar Ramoshttps://ww2.mathworks.cn/matlabcentral/profile/authors/16743596tag:ww2.mathworks.cn,2005:Question/5961012020-09-18T15:54:49Z2020-09-18T19:41:09ZIs it possible to add a custom button in the Simulink's model editor Explorer BarHello,
Coworkers and I are looking for a way to add a custom button in the Explorer bar (The gray bar on the left of the Model Editor featuring a Zoom, Fit to View, Sample Time, ...).
The upper toolstrip would also be a good candidate if it's impossible to customize the Explorer bar.
Context :
We are building models that has many constraints/rules. The constraint's verifications are being automated via Scripts.
Ideal solution :
The general idea is to have a button that acts as an indicator that would always be present on the screen and change colour when a rule is broken. We want to have minimal impact on the designer's model therefore custom subsystem are out of the question. Clicking the button would lead to a list of broken rules with dynamic links to blocks that breaks a rule.
We already have the knowledge to build the button's callback, what we would like to know is :
Can we add a button to the Explorer bar ?
If we can't , can we add a button to the toolstrip ?
Can buttons change icon dynamically ?
Thank you for your time,
P Lepage.P Lepagehttps://ww2.mathworks.cn/matlabcentral/profile/authors/19608904tag:ww2.mathworks.cn,2005:Question/5961762020-09-18T19:29:22Z2020-09-18T19:37:34Zplotting multiple vectors on one graphy1 =
308.0035
301.1535
301.0850
296.2900
293.5500
y2 =
313.8800
305.8800
305.8000
300.2000
297.0000
y3 =
325.0035
318.1535
318.0850
313.2900
310.5500
im not sure how to plot these on one graph?Steve Avilesmejiahttps://ww2.mathworks.cn/matlabcentral/profile/authors/17944317tag:ww2.mathworks.cn,2005:Question/5961612020-09-18T18:01:01Z2020-09-18T19:25:30ZWrite a MATLAB algorithm takes as input the vector x and computes C rowwiseSay I have a vector x in R^3, such that x = [1 2 3]. I want to form from x, a matrix C = [1 2 3; 3 1 2; 2 3 1]. So, basically, the pattern here is that the first row of C is the vector itself, then the last entry of the first row is the first entry of the second row and the numbers (1 and 2) get shifted, and then the last entry of the second row is the first entry of the third row and the numbers (3 and 1) get shifted.
I want to write a general algorithm for any vector x in R^n, so this is what I have written:
function [C] = rowwise(x)
n = length(x);
C(1,:) = x;
for i = 2:n
for j = 1:n
C(i,j) = C(i-1,"?");
end
end
I don't know what to put instead of the question mark. And is my algorithm correct? Any other ways, please? And how to compute that same matrix C but columnwise? Thank youPascale Bou Chahinehttps://ww2.mathworks.cn/matlabcentral/profile/authors/16075610tag:ww2.mathworks.cn,2005:Question/5949042020-09-16T18:20:53Z2020-09-18T19:22:02Zimage a set of matrix variables after loading them in.Benjamin Richhttps://ww2.mathworks.cn/matlabcentral/profile/authors/18697037tag:ww2.mathworks.cn,2005:Question/5961372020-09-18T17:26:34Z2020-09-18T19:21:56ZHow to go through each element of a vector without a for loopI would like to write the following code without a for loop. Thanks in advance!
function fh = poly_fun(p)
function polynomial = poly(x)
polynomial = 0;
for ii = 1:length(p)
polynomial = polynomial + p(ii) .* x.^(ii-1);
end
end
fh = @poly;
endJesús Alejandro Rodríguez Moraleshttps://ww2.mathworks.cn/matlabcentral/profile/authors/14016739tag:ww2.mathworks.cn,2005:Question/5960952020-09-18T15:53:27Z2020-09-18T19:20:39ZCirculant Matrix [Column Wise Traversal]Below is the row wise circulant matrix algorithm :
function C= circulant(x)
n=length(x);
C=zeros(n,n);
C(1,:)=x;
for i=2:n
C(i, :)=[C(i-1, n) C(i-1, 1:n-1)];
end
How can I compute the circulant matrix column wise based on what I wrote for the circulant matrix computed row wise?Tarek Hajj Shehadihttps://ww2.mathworks.cn/matlabcentral/profile/authors/18690627tag:ww2.mathworks.cn,2005:Question/4710472019-07-10T10:07:02Z2020-09-18T19:18:20ZWhat is crystal ball?I have seen some comments by some of the answered referring to crystal ball, been bugging for days. Does it actually suggest you a solution? Or is it just my hallucination? Can it be only obtained by certain people? I feel it as some kind of superpower 🦹♂️ madhan ravihttps://ww2.mathworks.cn/matlabcentral/profile/authors/12308260tag:ww2.mathworks.cn,2005:Question/5960082020-09-18T13:13:18Z2020-09-18T19:08:03ZUndefined function 'fmmod' for input arguments of type 'double'.Hi I am getting error when typing such code for multiplexing on matlab. The line on which error is encountered is :-
parfor i=1:nos
y(i,:)=fmmod(m(i,:),cfreq(1,i),10*cfreq(1,i),freqdev);
end
Requested to suggest solution to the above problemAnkit Guptahttps://ww2.mathworks.cn/matlabcentral/profile/authors/19289430tag:ww2.mathworks.cn,2005:Question/5961642020-09-18T18:29:45Z2020-09-18T19:05:10ZError with ODE and narginHello, can anyone help me out with this.?
function xdot = glucoseff(t,x)
p1=0.028735;
p2=0.028344;
p3=5.0353e-5;
gb=200;
ib=0;
n=0.10;
vi=12;
a=0:0.1:10
ug=exp(-a);
g=x(1);
y=x(2);
i=x(3);
%
%odes
%
dgdt=(-p1*g)-(t*g)+(p1*gb)+ug;
dydt=(-p2*y)+(p3*i)-(p3*ib);
didt=(-n*i)+ui/vi;
xdot = [dgdt; dydt; didt];
end
clc;
x0=[200;0;10];
[t,x] = ode45('glucoseff',[0 10],x0);
plot(x(:,1));
plot(x(:,2));
plot(x(:,3));
I don't understand the error :
Error using nargin
Error: File: glucoseff.m Line: 1 Column: 1
Function definitions are not permitted in this context.
Error in odearguments (line 60)
if (nargin(ode) == 2)
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in glucose_main (line 4)
[t,x] = ode45('glucoseff',[0 10],x0);Divya Noonelahttps://ww2.mathworks.cn/matlabcentral/profile/authors/19610462tag:ww2.mathworks.cn,2005:Question/5748522020-08-04T08:45:13Z2020-09-18T18:50:26ZHow can I use sliders to do interactive plots from a structure array?I have a structure array containing a B number of matrixes of [MxN] data, where M is different for every set and N is the same for every set of data.
I would like to have only one plot, where using two sliders I can choose between the B sets of data and N columns. I have only found examples of how to use a slider to update a plot changing a parameter (like the damping factor of a sinusoid), but nothing useful for my case.Alessandro Giacettihttps://ww2.mathworks.cn/matlabcentral/profile/authors/9848711tag:ww2.mathworks.cn,2005:Question/3684042017-11-21T15:50:17Z2020-09-18T18:45:40ZHide waitbar in Live EditorHi. Is there any way to hide the waitbar() in the live script itself while maintaining it as a separate figure?
What I have is:
<</matlabcentral/answers/uploaded_files/95551/Ihave.PNG>>
Jaime Lópezhttps://ww2.mathworks.cn/matlabcentral/profile/authors/8741699tag:ww2.mathworks.cn,2005:Question/5938332020-09-15T06:44:27Z2020-09-18T18:41:11Zparsim() with fast restart returns different resultsI am running multiple simulations using parsim() with fast restart to accelerate execution. However, I have noticed that using parsim() with fast restart produces different results compared to sim() and parsim() without fast restart. I have attached a simple model containing only SimEvents blocks and the code for running it. The model has a variable named InterGenerationTime, which is used by the Period field of the Entity Generator block. A SimulationInput object is used to set InterGenerationTime for different experiments. The To Workspace block records the number of entities generated by the block.
After running the code, the following figure is obtained.
The first two lines are just as expected, but the third line (parsim() with fast restart) is not. I assume there is something wrong with my implementation. Any help is appreciated. Abdolkarim Mohammadi-Balanihttps://ww2.mathworks.cn/matlabcentral/profile/authors/14675656tag:ww2.mathworks.cn,2005:Question/5959872020-09-18T12:50:24Z2020-09-18T18:40:23ZConvert red portion to white and the background to black . Second part is to detect road sign and put bounding box on it. I need to extract the road sign from an image. Can someone help me with this as I am new to matlab.renit anthonyhttps://ww2.mathworks.cn/matlabcentral/profile/authors/16962317tag:ww2.mathworks.cn,2005:Question/3311732017-03-22T02:01:12Z2020-09-18T18:37:17ZHow to calculate the pixels occured by white color in binary imageAfter converting the image to binary image and my primary aim is count the area covered by the white color and the black color in the binary image.
For Example, we have performed edge detection on the image and we got an output image in binary image. I want to calculate the area of the edge in the image which are in white.ABDUL WAHID MOHAMMEDhttps://ww2.mathworks.cn/matlabcentral/profile/authors/8816058tag:ww2.mathworks.cn,2005:Question/5953872020-09-17T12:42:39Z2020-09-18T18:34:32ZCopy results from a .mat file to existing excel fileHello, I have a .mat file (please check the attached script which produces it) as an output and I want to export the results into an existing excel sheet. Run1 and Run2 in the image are the results from previous simulations which are saved in .mat file everytime i run my script. I entered those 2 manually and I can't find a way to export by writing a script. The case names and number of outputs are same everytime, only the output changes. Thank you very much for your help. (Matlab version: R2018b)
Kezi Knshttps://ww2.mathworks.cn/matlabcentral/profile/authors/18967817tag:ww2.mathworks.cn,2005:Question/5960292020-09-18T13:41:52Z2020-09-18T18:32:35Zhow to find the next maximum value in column of the matrix which is different at the index of the firstHi!
I have an N * M matrix, i want to find the maximum value in each column,if the index of the first max value is the same with the others,i will find the next maximum value in those columns.
SINR =
0.3170 0.1029 0.0780 0.0014 0.0303
0.0666 0.1213 0.2206 0.4729 0.0542
0.0157 0.0109 0.2463 0.2058 0.5439
0.0404 0.1542 0.1665 0.0251 0.1449
0.0448 0.0264 0.0024 0.0532 0.0341
0.1038 0.0240 0.0028 0.1512 0.0965
0.1099 0.0503 0.2834 0.0706 0.0887
0.0324 0.2983 0.0452 0.0719 0.0344
0.4190 0.4786 0.1560 0.0094 0.0996
0.0868 0.0037 0.0024 0.1878 0.1287
SINRmax =
0.4190 0.4786 0.2834 0.4729 0.5439
0.3170 0.2983 0.2463 0.2058 0.1449
0.1099 0.1542 0.2206 0.1878 0.1287
idx1 =
9 9 7 2 3
1 8 3 3 4
7 4 2 10 10
as we see the index of the max value in column 1 is the same in column 2 ,in this case i will choose the second max value (index 8) for column 2 .
the output : put only the max value of each column and all other values at zero
0 0 0 0 0
0 0 0 0.4729 0
0 0 0 0 0.5439
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0.2834 0 0
0 0.2983 0 0 0
0.4190 0 0 0 0
0 0 0 0 0
there is a function that allows me to do that?
can you help me please insaf rzighttps://ww2.mathworks.cn/matlabcentral/profile/authors/17700162tag:ww2.mathworks.cn,2005:Question/908732013-10-20T19:44:04Z2020-09-18T18:26:39ZObject-counting in image processing.I am doing a project on object-counting from images. For that, I have taken two images- one is the background containing no objects and the other containing some objects(toy-cars) over it.
Background Image:
<</matlabcentral/answers/uploaded_files/848/bg1.png>>
------------------------------------------------------------
Image with objects over it:
<</matlabcentral/answers/uploaded_files/849/Snap5.png>>
The difference-image between the two images is taken and converted to black-and-white using a threshold value. The problem is that some of the pixels inside the objects match with the background and so these pixels are also getting subtracted completely and as a result, some black pixels are occurring inside the objects as you can see from the b/w image below and so the objects are getting divided into parts.
<</matlabcentral/answers/uploaded_files/847/absdiff_bw.png>>
I need each object to occur as one object so that we get the exact no of objects. Can someone please help me regarding this.
The code I have used is below:
I = imread('Snap5.png');
J = imread('bg1.png');
K = imabsdiff(I,J);
th = graythresh(K);
L = im2bw(K,th);
[LabeledIm,ConnectedObj] = bwlabel(L,4);
coloredLabels = label2rgb (LabeledIm, 'hsv', 'k', 'shuffle');
ConnectedObj
figure,
subplot(221), imshow(K), title('Difference'),
subplot(222), imshow(L), title('Thresholded BW'),
subplot(223), imshow(coloredLabels), title('Color-labeled Objects');Kangkanhttps://ww2.mathworks.cn/matlabcentral/profile/authors/4722430