https://de.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2017-02-20T20:06:36Ztag:de.mathworks.com,2005:Question/3260242017-02-20T20:06:34Z2017-02-20T20:06:34ZHow can correctly open a GUIDE file (.fig) created in a different screen size?<p>I created a GUI using Matlab in a Mac computer, with a big screen size.
For all the elements in the GUI I have set FontUnits to normalized.</p><p>And I also selected Tools->GUI Options-> Resize behavior: Proportional.</p><p>When I open the .fig to edit in Matlab (guide my_file.fig) on a Linux computer with a smaller screen (different resolution) it looks wrong:</p><img src = "/matlabcentral/answers/uploaded_files/70388/Wrong.png"><p>And this is how it looks like in the Mac computer:</p><img src = "/matlabcentral/answers/uploaded_files/70390/Right.png"><p>Any ideas on how to make it open correctly in the Linux computer?</p><p>Thank you very much</p>Raphaelhttps://de.mathworks.com/matlabcentral/profile/authors/5083029-raphaeltag:de.mathworks.com,2005:Question/3260112017-02-20T18:23:21Z2017-02-20T20:06:09Zhello please any one can help me<p>I have a text and after I arrangement the text descend so after I found the frequency I want each frequency besides the word</p>hiba rashedhttps://de.mathworks.com/matlabcentral/profile/authors/9027478-hiba-rashedtag:de.mathworks.com,2005:Question/3259052017-02-20T07:29:46Z2017-02-20T20:02:15ZDistributed Computing with RamDisk<p>Hello,</p><p>One of my projects involves heavy computational tasks which luckily can be parallelized.
After optimizing the code for 'parfor' usage, i can get a nice factor of ~ Ncores/3.
The bottleneck of squeezing even more lies (i'm almost sure) in the following: although the code optimization reduced the amount of data <b>sent</b> to each worker, the calculation's <b>output</b> is large (100MB-1GB), and probably can't be dramatically reduced. So, large overheads occur, stemming from data transfer (an indication to this can be seen when the workers seem to be finished, but one processor still works to full capacity for a long time before exiting the parfor loop is exited).
my question(s):
1. Is my hypothesis correct? Meaning - is this due to the fact that parfor writes temporary data files to the HD?
2. if i'm correct, RamDisk can prove beneficial (i have A LOT of RAM, 512GB). How do i 'tell' the distributed computing to use the RAM virtual drive?</p><p>Much appreciated,
Yanir H.</p>Yanir Hainickhttps://de.mathworks.com/matlabcentral/profile/authors/3881686-yanir-hainicktag:de.mathworks.com,2005:Question/3260232017-02-20T20:00:22Z2017-02-20T20:06:36ZHow to pass a variable from one file to another?<p>Hi all,
I have a matlab function block in Simulink with a feedback. The input to the function is a constant that changes with the time. The function calls another function includes ode15s (File1) that must get their equations from another file (File2). I want to pass the value of B from the main matlab function file to File2 to be used there.
I used global but that did not work. Any idea?</p><p>Matlab Function File:</p><pre class="language-matlab">function y = fcn(B)
...
y=File1
%-----------------------------
</pre><p>File 1</p><pre class="language-matlab">function [t,x]=File1
....
[t,x] = ode15s(@File2,tspan,x0,opt);
%-----------------------------------
</pre><p>File2</p><pre class="language-matlab">function out= File2(t,x)
...
out=[some equations that use "B" as a constant]
%-----------------------------------------------------
</pre><img src = "/matlabcentral/answers/uploaded_files/70389/xx.png">Ismaelhttps://de.mathworks.com/matlabcentral/profile/authors/1344148-ismaeltag:de.mathworks.com,2005:Question/3260222017-02-20T19:55:47Z2017-02-20T19:55:47Zwhat does this mean as an expression of regexp function <Node>(.*?)</Node> ?<p>NODE = struct('Info',regexp(FILE,'<Node>(.*?)</Node>','match'));
NODE(b).ID = regexp(NODE(b).Info,'(?<=<NodeID>)(.*?)(?=</NodeID>)','match');</p><p>FILE is missing here and I'm trying to</p><p>build it.</p>Salma Gamalhttps://de.mathworks.com/matlabcentral/profile/authors/8972577-salma-gamaltag:de.mathworks.com,2005:Question/3258482017-02-19T19:29:48Z2017-02-20T19:49:14Zchanging the scaling in the plot permenantly<p>Hello, when i plot a graph each time i manually have to change the axes scaling ,so it will show not every 5 [0,5,10]
but each one [0,1,2,3,4,5,6,7,8,9,10]
how can i control that with a command?</p><p>thanks</p>fima vhttps://de.mathworks.com/matlabcentral/profile/authors/8659326-fima-vtag:de.mathworks.com,2005:Question/3260122017-02-20T18:26:01Z2017-02-20T19:41:50Zcreating dye distribution profile with image processing<p>Hi All. I have two photos taken from a sandbox.the first one is reference and second one is the same sandbox after injection of dye which is blue. I did the following:
ref=imread('ref.jpg');
p1=imread('photo.jpg');
dif=ref(:,:,:)-p1(:,:,:);
imshow(dif)</p><p>since everything is the same in both pictures except dye, I expect to see the dye distribution by subtracting second photo from reference photo which doesnt have any dye but at the end I got a very black picture. does anybody know how to do this? I am a beginner so any help would be appreciated.
Thanks.</p>melody Sharifihttps://de.mathworks.com/matlabcentral/profile/authors/9741748-melody-sharifitag:de.mathworks.com,2005:Question/3258982017-02-20T06:53:34Z2017-02-20T19:40:42Zode15s is not supported when used in matlab-fn block in simulink<p>I have a code solves DAEs using ode15s fn. However, when I copy it into matlab function block in simulink, it does not work and this is the error I got:
"The function 'ode15s' is not supported for standalone code generation. See the documentation for coder.extrinsic to learn how you can use this function in simulation."
I read the aforementioned documentation but I could not use it in my code. Any experience from you would be greatly appreciated.
Thanks</p>Ismaelhttps://de.mathworks.com/matlabcentral/profile/authors/1344148-ismaeltag:de.mathworks.com,2005:Question/3258102017-02-19T14:06:29Z2017-02-20T19:39:45Zhow to calculate height of a crop (like wheat,rice etc)? if i have a side view of the crops<p>please help me with an algorithm to calculate height from the ground</p>Sharad Chttps://de.mathworks.com/matlabcentral/profile/authors/9755563-sharad-ctag:de.mathworks.com,2005:Question/3260092017-02-20T18:20:31Z2017-02-20T19:39:37ZImproving fitting of curve to data <p>Hi, I need to fit curve to data, the curve has to be of power-law form with non-constant exponent, which is some function of x (x is the independent variable), the curve form is a*x^(n(x)) where a is constant and n can be any function of x. I use 'fittype' and then 'fit' and get general fit, but it's not good enough. How can I improve the fitting?</p><p>Best Regards,</p>Roihttps://de.mathworks.com/matlabcentral/profile/authors/5524278-roitag:de.mathworks.com,2005:Question/3260172017-02-20T19:00:21Z2017-02-20T19:39:13ZHow to select odd numbers in a row<p>Hi,
I need to write a function that returns an output, which is the square root of the mean of the
squares of the first nn positive <b>odd</b> integers. nn is a positive integer and is the only input
argument. If nn is 3, my function needs to compute and return the square root of
the average of the numbers 1, 9, and 25. (Because 1, 3 and 5 are the first 3 odd integers)</p><p>So far I have:</p><p>function orms = odd_rms(nn)</p><p>h=[1:nn]</p><p>h=h.*h</p><p>orms=(sum(h(:)))</p><p>orms=sqrt(orms/nn)</p><p>end</p><p>However, I am not sure how to select the odd numbers only. I tried using mod, but that didn't work. Maybe I used it wrong. I am also not supposed to use the built-in function rms.</p><p>Thanks a lot!!!</p>JGrafhttps://de.mathworks.com/matlabcentral/profile/authors/4063487-jgraftag:de.mathworks.com,2005:Question/3259452017-02-20T11:10:27Z2017-02-20T19:38:45Zselecting a random nearest neighbour cell and setting a rule to it <p>I am trying to write up code for Stochastic Model of a Cellular Automata. My problem is I have 5 cells in the middle of Matrix called x (these are =1) and the outer cells surrounding it in the matrix are empty (=0.) I need to select randomly an x cell (=1) and <b>randomly</b> select a cell that is 0 or empty right next to it.</p><p>I have been trying this
x(3,4)=1 %% not an empty cell
if (x(i-1,j) or x(i+1,j) or x(i,j-1) or x(i,j+1) =0</p><p>%% pick one and set it to 1</p><p>say: x(3,2) = 0
now: x(3,2) = 1</p>Cathy O Connellhttps://de.mathworks.com/matlabcentral/profile/authors/9751157-cathy-o-connelltag:de.mathworks.com,2005:Question/3253752017-02-16T11:17:12Z2017-02-20T19:33:54ZHow can I rapidly filter a sorted vector for elements separated by a minimum value, processing one-way from the first value?<p>Using MATLAB R2012b, I have a (large) sorted vector of elements. Starting from the initial value, I need to discard all elements that are within some particular range of any previous undiscarded element. Simply looking for any set with the given minimum separation will not give the unique solution I require.</p><p>(Slow, but obvious) MWE:</p><pre class="language-matlab">function vec2 = testfun(vec,threshold)
idx = 0.1;
vec2 = vec;
while not(isempty(idx));
testdiff = diff(vec2);
idx = find(testdiff<threshold,1);
vec2(idx+1) = [];
end
end
</pre><p>When I call this on</p><pre class="language-matlab">vec = [1,13,27,30,33,39,53,54,100];
threshold = 25;
</pre><p>I should only retain:</p><pre class="language-matlab">vec2 == [1,27,53,100]
</pre><p>but calling</p><pre class="language-matlab">testfun(vec,10)
</pre><p>should give me</p><pre class="language-matlab">vec2 = [1, 13, 27, 39, 53, 100]
</pre><p>When I call it with a script to randomly generate larger vectors:</p><pre class="language-matlab">numval = 1e5;
threshold = 25;
vec = sort(rand(numval,1).*numval*1e2);
vec2 = testfun(vec,threshold);
</pre><p>the profiler indicates the following breakdown within the function:</p><pre class="language-matlab">vec2(idx+1) = []; 66%
dx = find(vecdiff<thresho... 20%
vecdiff = diff(vec2); 12%
</pre><p>Clearly, the re-indexing and allocation of vec2 after deleting elements is slow. Yet, if I don't take those elements out (e.g., I could set them = 0 instead of []), I have to find a way to ignore negative and zero elements in the diff output, but continue to search for results below the threshold value from the previous retained element. The total runtime in the function appears to behave quadratically, although the idx = find() line begins to take up more of the total time as the length of the vector increases (517s, 46/40/13% for numval = 4e5).</p>Danielhttps://de.mathworks.com/matlabcentral/profile/authors/3828155-danieltag:de.mathworks.com,2005:Question/3259702017-02-20T13:44:54Z2017-02-20T19:22:18ZCalling user functions recursively<p>I have user created functions called f11(), f12(), f13(), f21(), f22(), f23()...
I want to call these function recursively
for i=1 to n
for j=j to m
eval(fij())
I have tried with the eval() function. It does not work.
Could someone help me? thank you</p>Isabelle Armanvillehttps://de.mathworks.com/matlabcentral/profile/authors/3002868-isabelle-armanvilletag:de.mathworks.com,2005:Question/3260202017-02-20T19:17:40Z2017-02-20T19:18:40ZCalculate the value of a Student test and Fisher test<p>Hello! I want to calculate the value of a student test with 10 degree of freedom at the quantile (aplha) 0.01: t (10; 0.01). So if I have this value how can I calculate alpha correlated under matlab. I have the same question for the Fisher test. Thanks</p>amine&&https://de.mathworks.com/matlabcentral/profile/authors/6313651-aminetag:de.mathworks.com,2005:Question/3260162017-02-20T18:58:22Z2017-02-20T19:16:47ZLost signal in simulink scope<p>How can I fix this problem from simulink scope, it lost signal from 0 to 27s (the picture)</p><img src = "/matlabcentral/answers/uploaded_files/70380/Problem.PNG">Danh Lamhttps://de.mathworks.com/matlabcentral/profile/authors/7695939-danh-lamtag:de.mathworks.com,2005:Question/3260192017-02-20T19:16:10Z2017-02-20T19:16:10Zhow do I move mixed (numeric, categorical, logical} data into a table for subsequent analysis<p>I am using the adult incomes dataset. It contains numeric and nominal data. It also contains a nominal/logical variable (did income exceed 50k?). fitglm works with a table object. How to I get the appropriate column flags into a table for analysis?</p>Richard Palmerhttps://de.mathworks.com/matlabcentral/profile/authors/6329652-richard-palmertag:de.mathworks.com,2005:Question/3260182017-02-20T19:15:37Z2017-02-20T19:15:37Zhow do one efficiently implement a queue?<p>Hi, I'm implementing a wavefront algorithm and I need a queue for the open list.
I know that shrinking and enlarging an array, to simulate a queue harms performance. Is there another way to do that?</p><p>this is my pseudo-code for the wavefront algorithm:</p><p>-----------------</p><p>costs = zeros(height, width);</p><p>adiacients = [ 0 1; 1 0; 1 1; 1 -1; 0 -1; -1 0; -1 -1; -1 1];</p><p>open_list = target_point; % goal</p><p>j = 2; % costs</p><p>while not(isempty(open))</p><pre> x = pop(open_list);</pre><pre> for i=1:length(adiacients)</pre><pre> current = x + adiacients(i);</pre><pre> if inside_map(current) and costs(current(1), current(2)) == 0</pre><pre> costs(current(1) current(2)) = j;</pre><pre> insert(open, current);</pre><pre> end</pre><pre> end</pre><pre> j++;</pre><p>end</p>Carlo Alessihttps://de.mathworks.com/matlabcentral/profile/authors/9706216-carlo-alessitag:de.mathworks.com,2005:Question/728672013-04-20T06:14:02Z2017-02-20T19:09:44ZCode to count number of heads(people) present in a image<p>I want a matlab program which will count number of heads present in image and not other things present such as trees,other objects etc.please send me entire code.</p>Rohit Bhidehttps://de.mathworks.com/matlabcentral/profile/authors/4247334-rohit-bhidetag:de.mathworks.com,2005:Question/3259622017-02-20T13:06:44Z2017-02-20T19:09:03ZHow can I concatenate two or more arrays without using num2str?<p>For example if I have two vertical arrays:</p><p>A = [1;2]
B = [3;4]</p><p>I need this output:</p><p>C = [13; 24]</p><p>The problem is that my arrays have many rows, thus num2str is too slow. What can I do? Thanks!!!</p>Adrianohttps://de.mathworks.com/matlabcentral/profile/authors/5461029-adrianotag:de.mathworks.com,2005:Question/3260072017-02-20T18:06:56Z2017-02-20T19:04:45ZRotation around polygon loop<pre> theta = linspace( pi, -pi, 10);
r = 5;
x = r*cos(theta);
y = r*sin(theta);
plot(x,y,'r');
axis equal;
hold on;</pre><pre> theta = linspace( pi, -pi, 100);
x = cos(theta/2);
y = sin(theta/2);
npts = 10;
rit = [round(1:length(theta)/npts:length(theta))];
rit = [x(rit);y(rit)];
lft = [round(1:length(theta)/npts:length(theta))];
lft = [-x(lft);y(lft)];
filename = 'circle.gif';</pre><pre> for i = 1:npts
plot([rit(1,i) lft(1,i)],[rit(2,i) lft(2,i)], 'b.-')
axis equal;
hold on;
pause(.01)
drawnow
frame = getframe(1);
im = frame2im(frame);
[imind,cm] = rgb2ind(im,256);</pre><pre class="language-matlab">end
</pre><p>The code above creates a red polygon with 9 sides and a short animation of a circle in the middle. What I am trying to do it have a continuous loop run where the circle will move from the middle of a side to the middle of the next side of the polygon. It will continuously go around the polygon. I am having a lot of trouble and help would be appreciated.</p>John Abehttps://de.mathworks.com/matlabcentral/profile/authors/9718690-john-abetag:de.mathworks.com,2005:Question/3259222017-02-20T09:19:43Z2017-02-20T19:01:23ZError in Recursion saying Output argument "y" (and maybe others) not assigned during call to "recFunc".<p>Hello Everybody!</p><p>I am trying to find the state probabilities (Markov Chain) of a system through a recursive function written below.
What I want to do is to initialize the first state and then through transition probability (denoted by TransProb) to the next state.</p><p>But my recursion doesn't work and receive an error saying:</p><p><i>Output argument "y" (and maybe others) not assigned during call to "recFunc"</i></p><p>which means that I am not assigning anything to the output of this function "y".</p><pre> function y = recFunc(cu, ru, au, bu, u, n, p, omega)</pre><pre> if (p == 1)
if (u == n-1)
y = TransProb(cu, au, bu, u, QProb(omega, n, u), ru);
else
cu2 = cu-bu;
ru2 = ru - au + bu;</pre><pre> for au2 = 1:ru2
for bu2 = 0:cu2
y = y + TransProb(cu2, au2, bu2, u, QProb(omega, n, u), ru2);
end
end
end
else
cu2 = cu-bu;
ru2 = ru - au + bu;</pre><pre> for au2 = 1:ru2
for bu2 = 0:cu2
y = y + TransProb(cu, au, bu, u + p - 1, QProb(omega, n, u + p - 1), ru)...
* recFunc(cu2, ru2, au2, bu2, u, n, p-1, omega);
end
end
end</pre><p>end</p><p>I would be grateful if somebody can let me know what am I missing.</p>Shaham Shabanihttps://de.mathworks.com/matlabcentral/profile/authors/8456464-shaham-shabanitag:de.mathworks.com,2005:Question/3259872017-02-20T15:55:11Z2017-02-20T18:58:07Zwhile using FMINCON can we pass matrices as arguments while using calling objective function saved as seperate file <p>I'm using FMINCON . I saved my objective function in a seperate file. can i pass matrices as arguments while calling the objective function from main program.? if yes can i access the individual elements of the matrix?</p><p>call from main program is given below</p><p>[x,fval]=fmincon(@(x)fun(x,i,EC,PVpow,Pabrmp,Pplc,Psm,V1ref,k),x0,A,b,Aeq,beq,lb,ub,@(x)nonlcon(x,i,SOC1,PVpow,Pabrmp,Pplc,Psm,V1ref,k));</p><p>here PVpow,Pabrmp,Psm,Pplc are matrices</p>Krishna prasad Khttps://de.mathworks.com/matlabcentral/profile/authors/7273846-krishna-prasad-ktag:de.mathworks.com,2005:Question/3260152017-02-20T18:57:14Z2017-02-20T18:57:14ZHow to get projected depth values from camera toolbar while displaying a 3D mesh.<p>Hi all,
Suppose I have a 3D triangular mesh with some 'V' vertices and 'F' faces, 'V' contains 'XYZ' elements of the vertices, now using this 'Toolbox Graph', I am able to view my mesh nicely , by plot_mesh(V,F).
https://in.mathworks.com/matlabcentral/fileexchange/5355-toolbox-graph
Now I know that it uses camera toolbar of matlab to plot and show things , I can maximize , rotate etc and can set the view matrix manually and get a desired projective or orthographic view of the object.</p><p>I am still struggling on how to get the visible projection of the object in form of a depth image, More specifically something like raw depth map of the object (like simulating kinect [do not want actual simulation and noise modelling]), when viewed from an angle.</p><p>Any help will be highly appreciated.
Thanks :)</p>Gauravhttps://de.mathworks.com/matlabcentral/profile/authors/5340293-gauravtag:de.mathworks.com,2005:Question/3259162017-02-20T08:50:00Z2017-02-20T18:54:29ZBinary image, click on a pixel with ginput and redirect to the closest 1 in the matrix<p>Hi everyone! I'm trying to implement a code to select the closest pixel from a skeleton obtained with bwmorph.
So the idea is if I had:</p><pre> % A = [ 0 0 0 0 0 0 0 ; 0 1 1 1 1 1 0 ; 0 0 0 0 0 0 0 ];</pre><p>And I select with ginput command A(1,4), I'd like to obtain the value of A(2,4), because is the closest 1 to A(1,4) value.
Thanks a lot.</p>Alyssa Webbhttps://de.mathworks.com/matlabcentral/profile/authors/9606681-alyssa-webbtag:de.mathworks.com,2005:Question/3236542017-02-06T19:24:51Z2017-02-20T18:52:58ZCompiler and missing source files<p>Why does Matlab compiler not warn you when you run mcc and there is a missing source .m file? I ran it, (using the -v (verbose) switch). It compiles fine, no errors or warnings. Come to find out later that there was an mfile of mine that was not on the path, so the stand alone does not work. Why does Matlab not at least give an error or warning? Seems really strange...</p><p>Running 2014b on Mac os</p>Todd Weltihttps://de.mathworks.com/matlabcentral/profile/authors/57524-todd-weltitag:de.mathworks.com,2005:Question/3259992017-02-20T16:43:25Z2017-02-20T18:50:24Zim2double, double and adapthisteq<p>Hello,
I'm writing a PIV algorithm, I need to read two grayscale images divide them in interrogation windows and do cross-correlation using xcorr2. I'm having troubles converting the images from uint8 to double: firstly, I don't know if it is better to use double or im2double for converting the images, will corss-correlation give different results?
Secondly, I need to do adaptive histogram equalization, if I convert to double using double, before doing it, it produces bad output. If i use im2double instead, it does work; I then think it requires input of type double to be between 0 and 1, I searched the documentation, but it does not say anything about it. I am right?
Lastly, is there there any difference if I convert to double before or after the equalization?
Thank you very much.</p>CDhttps://de.mathworks.com/matlabcentral/profile/authors/4281717-cdtag:de.mathworks.com,2005:Question/3256772017-02-18T09:31:56Z2017-02-20T18:49:49ZI need need to get a mean and standard deviation my data but i there is error. I need the mean and standard deivation to plot the normal distribution for random24 and radon 8<pre> symbols = {'SMALL', 'MEDIUM', 'LARGE'};
range = 101; % <-- Or 101 if you want from 0 to 100 with 100 included
rndInd = randi(numel(symbols), range ,1);
st = symbols(rndInd);
strjoin(st);
random24 = strtrim(cellstr(num2str( randi(24, range, 1) )));
random8 = strtrim(cellstr(num2str( randi(8, range, 1) )));
b = num2cell(sort(randi(24, range, 1)));
B = cellfun(@num2str, b, 'UniformOutput', false);
%B = sort(random24)
st = [ st' B random8 ]</pre><pre> %% MEAN </pre><pre> mean8=mean(random8);
fprintf( 'Mean of Random 8 parking Duration is %f',mean8);</pre><pre> mean24=mean(random24);
fprintf( 'Mean of Random 24 Hours is %f',mean24);</pre><pre> %% Standard deviation
standDev8= std(random8);
fprintf( 'Standard Deviation of Random 1-8 Hours of parking Duration is %f',standDev8);
figure(1);
histogram(random8);
title('Histogram of Data for Random 1-8 Hours of parking Duration')</pre><pre> standDev24= std(random24);
fprintf( 'Standard Deviation of Random 24 Hours is %f',standDev24);
figure(2);
histogram(random24);
title('Histogram of Data for Random 24Hours ')</pre>Pang Chongjinghttps://de.mathworks.com/matlabcentral/profile/authors/8662087-pang-chongjingtag:de.mathworks.com,2005:Question/2978052016-07-30T20:28:29Z2017-02-20T18:48:39ZHow to calculate the curvature for this little black area? (Probability density function)<img src = "/matlabcentral/answers/uploaded_files/57006/sasa.jpg"><p>In this 2D image. I want to calculate the curvature for the black area inside. Is there any help please?</p>rana salehhttps://de.mathworks.com/matlabcentral/profile/authors/7665629-rana-salehtag:de.mathworks.com,2005:Question/3258762017-02-20T02:26:29Z2017-02-20T18:46:51Zi have a binary image with gird i want to select each segments in a grid<p>help me to extract or select a region in a grid because i want find foreground pixel in each grid in the attached image</p>Raghu Raohttps://de.mathworks.com/matlabcentral/profile/authors/9619059-raghu-raotag:de.mathworks.com,2005:Question/3259472017-02-20T11:28:04Z2017-02-20T18:46:09Zplot 2 vectors not same length<p>Hi all,</p><p>i would like to plot 2 vecotrs not the same length ( velocity with 412 elements and time with 380169 elements), i tried this with the "griddedInterpolant command" but it doesnt work. I want that time-vector to have the same lenght as velocity-vector if that possbile.
I will appreciate any help</p>Alexhttps://de.mathworks.com/matlabcentral/profile/authors/8513756-alextag:de.mathworks.com,2005:Question/3259712017-02-20T13:59:01Z2017-02-20T18:38:03ZHow can I plot 2D plot from three matrix?<p>I am trying to plot a 2D plot using three matrices but somehow I couldn't understand. I have three matrices and an array. Suppose,</p><pre class="language-matlab">A =
1 2 3
4 5 4
7 8 9
B =
2 3 13
5 11 10
9 7 6
C =
1 2 3
2 3 13
5 11 10
</pre><p>and an array</p><pre class="language-matlab">Y= [0.001 0.0002 0.0004].
</pre><p>Now I want to plot it in such a way that array values should be on y axis while against 0.001, 0.002 and 0.0004, the matrices value should be arranged. for examples, the</p><pre class="language-matlab">y=0.001, A(1,1)=1,
y=0.0002, B(1,1)=2
y=0.0004, C(1,1)=1
</pre><p>for a single line now similarly same process should go for A(i,j),B(i,j) and c(i,j) points using loop to plot all lines on a single figure.</p><p>Thanks</p>Zubair Nizamanihttps://de.mathworks.com/matlabcentral/profile/authors/7097991-zubair-nizamanitag:de.mathworks.com,2005:Question/3260142017-02-20T18:34:36Z2017-02-20T18:34:36ZSolving a system of 12 2nd order partial differential equations of two spatial variables in Matlab PDE Toolbox<p>Hello,</p><p>I need to solve a system of 12 second order partial differential equations. The system is of the form A*f,xx(x,y)+B*f,yy(x,y)+C*f,xy(x,y)=D, where A, B, C and D are coefficient matrices and f(x,y) is a vector of unknown functions that need to be solved f(x,y)^T=(f1(x,y) f2(x,y)...). Is it possible to solve such system of PDEs in Matlab Toolbox? The boundary conditions are of a mixed type.</p><p>Best regards</p><p>Rafal Sulwinski</p>Rafal Sulwinskihttps://de.mathworks.com/matlabcentral/profile/authors/4643707-rafal-sulwinskitag:de.mathworks.com,2005:Question/3260132017-02-20T18:34:02Z2017-02-20T18:34:02Zusing matlab simulink finding severity and impact of faults on current harmonics in inverter fed ac drive<p>can i get the simulink model for the attached file.
it is finding total harmonic distortion of vsi fed ac drive for different types of faults</p>Akash h.rhttps://de.mathworks.com/matlabcentral/profile/authors/8540536-akash-h-rtag:de.mathworks.com,2005:Question/3257902017-02-19T09:29:00Z2017-02-20T18:33:21ZSwapping from hist to histogram<p>Hi, under the recommendation of Steven Lord, I am trying to update my code and not use hist as the histogram function and instead use histogram</p><p>I previously did this:</p><pre class="language-matlab">[counts,xb]=hist(data(:,3),nbins); %IMHIST ONLY HANDLES 8 & 16 BIT IMAGES, NOT 12BIT
figure
ax1=subplot(1,2,1);
bar(xb,counts,'b','EdgeColor','b');
grid on
</pre><pre class="language-matlab">%Now get the max frequency.
mxC=max(counts);
indx=find(counts==mxC);
xmx=xb(indx);
hold on;
lineH1=plot([xmx xmx],ylim,'r--','LineWidth',1);
hold off
</pre><p>So when I swap over to the histogram function, I can get the y-axis values but not the x-axis values</p><pre class="language-matlab">h=histogram(data(:,3),nbins)
counts=h.Values % frequency (i.e. y-axis)
</pre><p>How do I get the mode of this histogram and plot it?</p><p>Thanks
Jason</p>Jasonhttps://de.mathworks.com/matlabcentral/profile/authors/1217570-jasontag:de.mathworks.com,2005:Question/3258132017-02-19T15:09:17Z2017-02-20T18:24:35ZDocumentation for splines could be improved<p>Hi</p><p>this is more a request/proposal than a question. It turned out yesterday when I asked about natural spline, that natural splines, as John pointed out, are supported by matlab, howver the documentation is not very helpful.</p><p>Natural splines are the first to be mentioned in many textbook, so help spline should say a word about it, it should also provide a link to csape, but it provides a link to splines, which provides then information about csape, but this is not enough. Maybe somebody of the Mathwork teams reads this and take notice.</p><p>thanks</p><p>Uwe Brauer</p>Uwe Brauerhttps://de.mathworks.com/matlabcentral/profile/authors/1399918-uwe-brauertag:de.mathworks.com,2005:Question/3260102017-02-20T18:21:03Z2017-02-20T18:21:03ZHow to average a column's data when they have the same value in another 2 column of a matrix?<p>Hi All,
I have some hourly meteorological data (like a matrix) for many years and I delete some of my data (rows) based on some criteria previously I mean not all my months have about 30 values. But I want an average for each month of each year. one of the columns shows the year and one shows the month. So I want to get an average of monthly tempreture in each year MEANS I want to average all values in the column 5 (temperature) that have the same values (at the same time) in column 1 (year) and column 2 (month). I should consider both values (year and month) simultaneously MEANS I need just an average temperature value for month 1 of year 1980 and so on. Any suggestion for an easy way?</p>Marmarhttps://de.mathworks.com/matlabcentral/profile/authors/4934936-marmartag:de.mathworks.com,2005:Question/3259502017-02-20T12:00:24Z2017-02-20T18:20:36ZFinding the time difference between both my functions<p>These are my 2 functions, is there a way of putting them into a script and comparing their running times?</p><pre> function nprimes(N)
n = 1;
nPrimes = 0; </pre><pre> while nPrimes < N
if isprime(n)
fprintf('%i\n',n)</pre><pre> nPrimes = nPrimes + 1;
end</pre><pre> n = n + 1;
end
end</pre><pre> function p = nprimes(N)
p = [];
if N == 1
p = 2;
elseif N == 2
p = [2 3];
else
pn1 = nprimes(N-1);
plast = pn1(end) + 1;
while ~isprime(plast)
plast = plast + 1;
end;
p = [nprimes(N-1), plast];
end;</pre>Jack Zimmermanhttps://de.mathworks.com/matlabcentral/profile/authors/8728229-jack-zimmermantag:de.mathworks.com,2005:Question/3260082017-02-20T18:19:51Z2017-02-20T18:19:51ZFROM EXCEL TO MATLAB AND FROM MATLAB TO EXCEL<p>Hy,</p><p>I want to transmit the data of an Ecxel sheet to Matlab to do a calculating. This excel is of 6 columns and 10000 lines (attached). I want MATLAB to take the data in the form of a matrice A(6,10000) and calculate the image of each line with a function (of 6 variables): HASSANE, in the following way:</p><p>{T_max_A=[];</p><p>parfor i=1:n</p><p>T_max_A(i)= HASSANE(A(i,:)); % Calcul of T_max for each line of the matrice A, n=10000 in our case</p><p>end</p><p>T_max_A}</p><p>After, I want that the 10000 calculated T_max_A will be transmitted to an Excel sheet with ine column and 10000 lines simply.</p><p>Reading is not always suffisant and I spen a lot of times without understanding anything. Can you tell me how to do practically "please"?</p><p>Thanks a lot.</p>moulay ELMOUKRIEhttps://de.mathworks.com/matlabcentral/profile/authors/9226782-moulay-elmoukrietag:de.mathworks.com,2005:Question/3248082017-02-13T16:38:10Z2017-02-20T18:18:31ZUsing fzero function to solve a nonlinear equation with two inputs <p>Hi,</p><p>I am trying to solve this non-linear equation for alpha using a range of values of X (0-100) [so that I can plot alpha vs X].</p><pre class="language-matlab">function y=equations(alpha)
</pre><pre class="language-matlab">[D, A, R] = geom();
[n, m] = setglbl();
[X] = setX();
</pre><pre> Ag = (R.^2)*(pi-alpha+0.5*sin(2*alpha)) ;
Sgw = 2*R*(pi-alpha) ;
Si = 2*R*sin(alpha) ;
Dg = 4*Ag/(Sgw+Si) ;
Al = (R.^2)*(alpha-0.5*sin(2*alpha)) ;
Slw = 2*R*alpha ;
Dl = 4*Al/Slw ;
ag = Ag/A ; </pre><pre class="language-matlab">y=((X.^2).*(1-ag).^(n-2)*(D/Dl).^(n+1))-(ag.^(m-2)*(D/Dg).^(m+1)*(1+(Dg*Si/Al)));
</pre><pre class="language-matlab">end
</pre><p>WHERE</p><pre class="language-matlab">function [X] = setX
global X ;
X=linspace(0,100,101) ;
end
</pre><p>AND</p><pre class="language-matlab">function [Cg, Cl, n, m] = setglbl
global Cg Cl n m
n=1;
m=1;
end
</pre><p>AND</p><pre class="language-matlab">function [D, A, R] = geom()
D = 0.3; %Pipe Diameter (m)
R = D/2; %Pipe Radius (m)
A = pi*(R^2); %Cross-sectional Area (m^2)
end
</pre><p>I KEEP GETTING ERRORS:</p><pre class="language-matlab">Error using fzero (line 301)
FZERO cannot continue because user-supplied function_handle ==> equations failed with the error below.
</pre><pre> *Matrix dimensions must agree.*
>> equations</pre><pre class="language-matlab">*Not enough input arguments.*
</pre><pre class="language-matlab">Error in equations (line 7)
Ag = (R.^2)*(pi-alpha+0.5*sin(2*alpha)) ; % [m^2] Cross-sectional area of gas phase in pipe
</pre><p>Does anyone have some advice on what the problem could be?</p><p>Should the X interval be defined differently? Or should X be used as a second input to the function?</p><p>Any help appreciated!</p>Egle Kirsaitehttps://de.mathworks.com/matlabcentral/profile/authors/9022553-egle-kirsaitetag:de.mathworks.com,2005:Question/760602013-05-16T19:05:08Z2017-02-20T18:17:09ZLinear Feedback Shift Register algorithm<p>I'm trying to code my own implementation of Linear Feedback Shift Register on Matlab in order to generate a pseudo-random sequence of numbers. Suppose I need to generate a sequence from 1 to 16,384 (2^14) in random order, my initial state is number 329 and the tap is 7.</p><p>This is the code I've got so far:</p><pre class="language-matlab">function [rndV] = lfsr(limit, init, tap)
X = -1;
rndV = init;
bits = nextpow2(limit);
while(X ~= init)
if(X == -1)
X = init;
end
a = bitget(X, bits);
b = bitget(X, tap);
X = bitshift(X,1,bits);
X = bitset(X,1,bitxor(a,b));
rndV = [rndV X];
end
end
</pre><p>The parameters are:</p><pre class="language-matlab">limit = 16,384
init = 329
tap = 7
</pre><p>If I get right LFSR, must the algorithm loop until the initial state is found again? Does this loop must generate all numbers between 1 and 16,384 in random order?</p><p>Something is wrong on my code or maybe I misunderstood LFSR algorithm, but I'm getting just 22 numbers in random order, then the initial state (329) is found again.</p><p>I want to achieve the same as described here <http://www.cs.princeton.edu/courses/archive/fall08/cos126/assignments/lfsr.html>but in matlab.Thanks!</p>Jorge Zapatahttps://de.mathworks.com/matlabcentral/profile/authors/3479955-jorge-zapatatag:de.mathworks.com,2005:Question/3221932017-01-27T13:46:40Z2017-02-20T18:10:50ZOutputting Drawing using image Processing <p>Hey guys,</p><p>I was trying to write a small script to output a room layout drawing (similar to the attached picture), Just wanted to get an opinion from you guys on weather or not this was possible.</p><p>Was thinking to create a new image and draw a room by drawing boxes and lines.
is this idea a bit far fetched? What would be your recommendation?</p><p>thanks in advance,
Sanchir</p>Sanchir Eganhttps://de.mathworks.com/matlabcentral/profile/authors/7817046-sanchir-egantag:de.mathworks.com,2005:Question/3259152017-02-20T08:36:24Z2017-02-20T18:09:56Zhow to find range of elements in each row of a matrix<p>i have a matrix of 8 x 5 and i want if there are at least two values in a row that lies between 6 and 8,then store the locations of those value else decrease the lower value from 6 to 5 and check if any value lies between 5 &8 else increase the upper value to 9 and check the values of a row lies between 7&9...I need to set the the range for each row and to store the location of the values in each row that lie in a specified range</p>studentambitioushttps://de.mathworks.com/matlabcentral/profile/authors/6818953-studentambitioustag:de.mathworks.com,2005:Question/3260032017-02-20T17:16:41Z2017-02-20T17:59:52ZHow to hide/unhide button group using callbacks in Push button?<p>I am trying to unhide visibility of Button Group ,but I am getting error as
"Error using matlab.ui.container.ButtonGroup/set
There is no Enable property on the ButtonGroup class."
How to unhide it ?</p>Pravin Kokanehttps://de.mathworks.com/matlabcentral/profile/authors/8499377-pravin-kokanetag:de.mathworks.com,2005:Question/3258022017-02-19T12:49:59Z2017-02-20T17:58:58ZObtaining a maximum value from the third column of an array which is in a cell<p>Hello,
I am trying to obtain a maximum value from from the third column of arrays which are in cells. However the number of arrays that are in these cells varies with the lowest number of arrays being 1. This is the code I am using to try and achieve this;</p><pre class="language-matlab">jpegFiles = dir('*.jpg');
numfiles = length(jpegFiles);
for I = 1:numfiles
img{I} = imread(jpegFiles(I).name);
B{I} = imbinarize(img{I},0.2); %converts image to binary image
%removes reflection
N{I} = bwconncomp(B{I}); %finds connected components in binary image
S{I} = regionprops(N{I},'Area'); %computes area of each component
for i = 1:length(S{I})
if S{I}(i,1).Area<=100000 %arbitrary
B{I}(N{I}.PixelIdxList{i}) = 0;
end
end;
IB{I} = imcomplement(B{I}); %inverts binary image
C{I} = IB{I}(1:305,1:end); %crops image
M{I} = bwconncomp(C{I});
stats{I} = regionprops(M{I},'BoundingBox'); %creates a box around the area of interest
for i = 1:length(stats{I});
A{I}(i) = (max(stats{I}.BoundingBox(1,3)));
end
% Z(I) = (max(A{I})-1)/66;
% Widths(I) = (stats{I}.BoundingBox(:,3)-1)/66;
% Heights(I) = (stats{I}.BoundingBox(:,4)-1)/66;
%
% Centroid(I) = (stats{I}.Centroid(:,2))/66;
end
</pre><p>The code takes a frame that have been produced from a video that has been taken, converts it to binary, inverts it and then creates a box around the region of interest. I then measure the width and height of this box. The error it is producing is:</p><pre class="language-matlab">Expected one output from a curly brace or dot indexing expression, but there were 19 results.
</pre><pre class="language-matlab">Error in Multiple_Frames (line 28)
A{I}(i) = (max(stats{I}.BoundingBox(1,3)));
</pre><p>The code works fine when there is a single array in each cell but produces an error when there is more than one array in one of the cells. Is there any way of combating this issue?</p><p>Also, is there any way of importing the different files (frames) in order when analysing them in matlab?</p><p>Any help would be much appreciated.</p><p>Kind regards</p><p>Liam</p>Liam Thurstonhttps://de.mathworks.com/matlabcentral/profile/authors/9680615-liam-thurstontag:de.mathworks.com,2005:Question/1368342014-06-21T08:16:45Z2017-02-20T17:55:32ZDetermine if using HG2<p>How can I determine if MATLAB or the current figure is using the new graphics pipeline, HG2? I need a function</p><pre> tf = ishg2(figure_handle)</pre><p>which should be backwards compatible, say to MATLAB 7.0, and also account for the fact that people can choose which rendering pipeline to use (HG1 or HG2) in newer MATLAB releases, so simply checking version number is not sufficient.</p>Oliver Woodfordhttps://de.mathworks.com/matlabcentral/profile/authors/1073021-oliver-woodfordtag:de.mathworks.com,2005:Question/3260022017-02-20T17:08:08Z2017-02-20T17:47:28Zhow to find the min of a vector without using built-in functions?<p>we are required to find the minimum of vector x1=[19 17 16 14 13 15 19] without using the built-in function. what will the m-function be and can it be done without loops ???</p>amjad alskafihttps://de.mathworks.com/matlabcentral/profile/authors/9759353-amjad-alskafitag:de.mathworks.com,2005:Question/1146922014-02-03T16:54:02Z2017-02-20T17:37:47Zmatlab codes for face detection from a web cam video<p>please TELL me the MATLAB Code to detect or track a face in a real time video using A webcam in MATLAB* I AM DOING MY PROJECT IN FACE RECOGNITION, BUT NOT GETTING HELP FROM ANYWHERE. Thank you....</p>sanjidahttps://de.mathworks.com/matlabcentral/profile/authors/4421113-sanjidatag:de.mathworks.com,2005:Question/2711002016-03-02T20:40:17Z2017-02-20T17:36:07ZMy EDITOR tab is disabled.<p>When I running my m file, and I break it to run line by line. I don't why my Step button (F10), step in, step out, and also Quit debugging are disabled. How can I turn it on?</p>Teeratorn Kadeethumhttps://de.mathworks.com/matlabcentral/profile/authors/6307906-teeratorn-kadeethumtag:de.mathworks.com,2005:Question/2757822016-03-28T12:12:42Z2017-02-20T17:30:17Zerror finding installer class<p>i tried to install trial version
and i recive the error:
"error finding installer class.
an exception occurred while looking for class."</p>amir roshttps://de.mathworks.com/matlabcentral/profile/authors/7923252-amir-ros