http://de.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2015-11-30T18:46:48Ztag:de.mathworks.com,2005:Question/2582352015-11-30T16:19:41Z2015-11-30T18:46:48ZSort cell array based on 2 columns with date and time (strings)<p>Hello, i have a cell array 395*8 cell.</p><p>Columns 3 and 4 have</p><p>'01/20/2014' '19:22:05.0120'</p><p>'01/15/2014' '19:22:20.8020'</p><p>'01/17/2014' '20:01:26.0630'</p><p>'01/16/2014' '20:04:21.1260'</p><p>and so on.</p><p>How can i sort them based firstly on column 3 and then column 4.</p><p>sortrows did not work</p><p>sortrows(cellname,[3 4]) because i have string values.</p>Christos Antonakopouloshttp://de.mathworks.com/matlabcentral/profile/authors/7285075-christos-antonakopoulostag:de.mathworks.com,2005:Question/2582542015-11-30T18:45:38Z2015-11-30T18:45:38ZExplain hysteresis logic in matlab with a sample simulink model <p>Please Expalin hysteresis logic in matlab with a sample simulink model</p>mettupalli Sriharshahttp://de.mathworks.com/matlabcentral/profile/authors/5374356-mettupalli-sriharshatag:de.mathworks.com,2005:Question/2582522015-11-30T18:27:30Z2015-11-30T18:44:49ZHow can I add a table in GUI asking the user to input the number of rows.<p>I am new to MATLAB. I am using GUIDE to create a GUI. I have an editable text box asking the user to input the number of rows. When the user types a number say 4, I would like a table to be created with 4 rows and two columns.
Basically, I have the text box to input the degrees of freedom of a robot manipulator. And when the user inputs 4, I would like to ask what kind of a joint it is (Revolute or prismatic). So next time when the user inputs 5, I would like to define the type of each joint. So for some input n ( n can be anything from 1,2,3,...) I would like the user to define the type of each joint.</p>Abhihttp://de.mathworks.com/matlabcentral/profile/authors/5590921-abhitag:de.mathworks.com,2005:Question/2577242015-11-27T00:17:42Z2015-11-30T18:44:05ZMultiply a set of data points in all directions<p>I am trying to generate a lattice from the position of molecules in a unit cell. I can get this to multiply along the x,y,z axes; my problem is that I don't know how to make the center of the coordinate system fill as well.</p><p>I have 2 atoms / molecule, with 4 molecules making up the unit cell.</p><p>My approach was to multiply first in the x and y directions, then fill the x-y plane and build up the z-direction from the x-y plane; I just don't know how I can code that effectively.</p><p>Any help/suggestions would be much appreciated, as I am doing this for my research.</p><p>Thank you!</p>lsutiger1http://de.mathworks.com/matlabcentral/profile/authors/7235972-lsutiger1tag:de.mathworks.com,2005:Question/531052012-11-07T23:29:28Z2015-11-30T18:43:40Zpre-processing steps in palm vein image ????<p>how can I show the vascular in binary palm vein image
I make this code and the vascular not apper in binary
>> I=imread('001_l_460_01.jpg');
>> figure,imshow(I);
>> level=graythresh(I);
>> bw=im2bw(I,level);
>> figure,imshow(bw);
>> roipoly(bw);
>> x=[408 514 708 598]
x =
408 514 708 598
>> y=[313 96 213 421]
y =
313 96 213 421
>> BW=poly2mask(x,y,576,768);
>> h=fspecial('unsharp');
>> I2=roifilt2(h,I,BW);
>> figure,imshow(I2);
what is the wrong???</p>mona zizohttp://de.mathworks.com/matlabcentral/profile/authors/3770282-mona-zizotag:de.mathworks.com,2005:Question/2557802015-11-18T14:59:24Z2015-11-30T18:43:08Zthe root finding using fsolve<p>is there any way using fsolve to get 'all' possible solutions for equations? it just shows me the closest root to the initial guess!</p>elahttp://de.mathworks.com/matlabcentral/profile/authors/5616735-elatag:de.mathworks.com,2005:Question/2582252015-11-30T14:48:56Z2015-11-30T18:40:22ZHow to trasform a cell array of cells in a matrix<p>Problem: I have a cell array and every cell of this array has an other cell that contains a string: I want to trasform the cell array in a matrix of strings. How can i do? I have tried to use cell2mat but matlab gives an error:</p><pre class="language-matlab">'Cannot support cell arrays containing cell arrays or objects.'
</pre>ely mayhttp://de.mathworks.com/matlabcentral/profile/authors/7327806-ely-maytag:de.mathworks.com,2005:Question/2582532015-11-30T18:34:49Z2015-11-30T18:34:49Zmemory block STM32F4<p>Hi,
I'm using embedded coder block set for STM32F4. I want to visualize the values of my certain variables in run-time. For that I want to copy the variable value to a particular memory address of my controller so that I can visualize it. I'm having problem in using the "memory copy" block of simulink library. Any help will be really appreciated.</p><p>Regards.</p>nouman sadiqhttp://de.mathworks.com/matlabcentral/profile/authors/5890850-nouman-sadiqtag:de.mathworks.com,2005:Question/2582482015-11-30T18:07:12Z2015-11-30T18:32:54ZIs it possible to assign an object to a struct type?<p>For example, I would like to do something like</p><pre class="language-matlab">h(1) = axes;
</pre><p>so that I could do something like</p><pre class="language-matlab">h(1).YLim = [-5,5];
</pre><p>My workaround is doing</p><pre class="language-matlab">ax(1).h = axes;
ax(1).h.YLim = [-5,5];
</pre><p>Thanks,
Denis</p>Denis Vashukhttp://de.mathworks.com/matlabcentral/profile/authors/5502776-denis-vashuktag:de.mathworks.com,2005:Question/2582502015-11-30T18:24:16Z2015-11-30T18:24:16ZWrong answers in my Simpson rule array? <pre class="language-matlab">clear;
f=@(x) exp(1/2*x);
a = 0;
b = 15*pi;
N = [10,20,60,100];
</pre><pre class="language-matlab">for k = 1:length(N);
h(k) = (b-a)/N(k);
end
</pre><pre class="language-matlab">for k=1:length(N);
Sum1(k)= 0;
Sum2(k) = 0;
for i=1:(N(k)-1)
xL = a + i*h(k);
if mod(i,2) == 0
Sum1(k) = Sum1(k) + f(xL);
else
Sum2(k) = Sum2(k) + f(xL);
end
end
Simp = (h(k)/3)*((f(a) + 2*Sum1(k) + 4*Sum2(k) + f(b)));
end
</pre><pre class="language-matlab">for k=1:length(N)
fprintf('For h = %5.1f the Simp is %5.1f ',h(k),Simp)
end
</pre><p>I want to run all 4 numbers in my array(my N values) however, every time i run my code i only get the answer for my last value(80), i really don't know where i have gone wrong,
thanks</p>Fawwaz Rjhttp://de.mathworks.com/matlabcentral/profile/authors/7145995-fawwaz-rjtag:de.mathworks.com,2005:Question/2582472015-11-30T18:03:51Z2015-11-30T18:19:03ZGenerate an array with infinite values<p>Hi, I'm wondering if is possible to generate an array that contains infinite values the values from 0+ to 1-.</p><p>Thanks in advance</p>Matteo Bredahttp://de.mathworks.com/matlabcentral/profile/authors/6536360-matteo-bredatag:de.mathworks.com,2005:Question/2582432015-11-30T17:11:17Z2015-11-30T18:13:58ZGradient method on matlab for estimating a,b?<p>I have x\dot=-ax+b*cost</p><p>and i want to estimate a,b with gradient method how can i do that please help me!!</p>Verisignhttp://de.mathworks.com/matlabcentral/profile/authors/7219150-verisigntag:de.mathworks.com,2005:Question/2582492015-11-30T18:08:44Z2015-11-30T18:08:44ZHow do I set boundary conditions for my bowling game? <p>I'm making a bowling game on MATLAB. So far I have set the images for the background and pins. How do I make the ball roll down the side alley in case it goes near the edge? I made equations to compare x values at a fixed y value but it has no effect. What would you suggest?</p>Abeeha Aamirhttp://de.mathworks.com/matlabcentral/profile/authors/7340913-abeeha-aamirtag:de.mathworks.com,2005:Question/2575082015-11-25T17:27:31Z2015-11-30T18:06:02ZLooking for something like a matrix version of randsample... [vectorization!]<p>If I have a vector w (length n) and I want to pick a single random number between 1 and n using w as the weights, I can do something like</p><pre class="language-matlab">idx = randsample(n,1,true,w)
</pre><p>and I'll get a number between 1 and n with probability w(idx)/sum(w). Great.</p><p>Similarly, I have a matrix W (size N x M, where each of N,M is in the thousands or so), and I want to draw M random numbers between 1 and N, with the columns of W acting as independent weight vectors. I could obviously do</p><pre class="language-matlab">idx = zeros(N,1);
for i = 1:M
idx(i) = randsample(N,1,true,W(:,i));
end
</pre><p>...but I'm going to be calling this literally <i>billions</i> of times, so I'm looking for some efficiency.</p><p>I know that an equivalent way to think of this is to take my W matrix, normalize the columns so that they sum to one, do a cumsum on the columns, select a vector of uniform random numbers using rand(1,M), and find the first row indices where they are greater than the cumsum values, but I don't know how to do that without using a loop and find():</p><pre class="language-matlab">W_normalized = bsxfun(@rdivide,W,sum(W,1));
W_cdf = cumsum(W,1);
x = rand(1,M);
C = bsxfun(@lt,x,W_cdf);
</pre><p>and then the first row of each column of C with a 1 in it is my random number, but I haven't had any luck doing that in an efficient, vectorized way (I've seen <a href = "http://www.mathworks.com/matlabcentral/newsreader/view_thread/289720">this thread</a>, but I think their conclusion to use a for-loop doesn't really seem to hold for larger matrices).</p><p>Any suggestions?</p><p>Thanks,
Dan</p>Dan Gianottihttp://de.mathworks.com/matlabcentral/profile/authors/3389198-dan-gianottitag:de.mathworks.com,2005:Question/2582412015-11-30T17:03:42Z2015-11-30T17:57:39Zi want to write a matlab function for the prime numbers without using the built in functions like isprime, so that i can enter a range of numbers and get the result that which of these are prime numbers, please help<p>please help me with writing a function for the output of prime numbers</p>Muhammad Owais Qadrihttp://de.mathworks.com/matlabcentral/profile/authors/7191879-muhammad-owais-qadritag:de.mathworks.com,2005:Question/2582402015-11-30T16:55:04Z2015-11-30T17:54:18ZHow to plot magnitude spectrum of a signal?<p>I want to plot magnitude spectrum. Let's say I want to generate two input signals with 100 Hz and 200 Hz.</p><pre class="language-matlab">x1 = cos(2*pi*100*[0:1/fsampling:1.23]);
x2 = cos(2*pi*200*[0:1/fsampling:1.23]);
x = x1 + x2;
x(end) = [];
[b,a] = butter(2,[0.6 0.7],'bandpass');
filtered_noise = filter(b,a,randn(1, length(x)*2));
y = (x + 0.5*filtered_noise(500:500+length(x)-1))/length(x)*2;
</pre><pre class="language-matlab">%plot first half of DFT (normalised frequency)
Y_mags = abs(fft(y));
num_bins = length(Y_mags);
plot([0:1/(num_bins/2 -1):1], Y_mags(1:num_bins/2)),grid on;
title('Magnitude spectrum of noisy signal');
xlabel('Normalised frequency (\pi rads/sample)');
ylabel('Magnitude');
</pre><img src = "/matlabcentral/answers/uploaded_files/41075/1.PNG"><p>My problem now is I don't really understand how the y-axis works. Why both 100 Hz and 200 Hz signals have magnitude of 1? Please help me!</p>Nur Fauzira Saidinhttp://de.mathworks.com/matlabcentral/profile/authors/6263286-nur-fauzira-saidintag:de.mathworks.com,2005:Question/2582462015-11-30T17:43:48Z2015-11-30T17:43:48ZImplemeting Factor Structure Model<p>I'm trying to implement the factor structure model using Gauss Quadrature or MCMC method as done by many in their research work.</p><p>The model is to find the effect of cognitive and non-cognitive abilities on labor market outcomes where cognitive and non-cognitive abilities are latent factors</p><pre> Earnings= βiXi + βcCognitivei + βnNonCognitivei + ϵi</pre><p>where X_i is a vector of controls</p><p>Now, one simple way that I know to implement the model is to use cognitive and non-cognitive test scores to find factor scores and use it as independent variable in above equation. But, this is not the way it is implemented in many of those papers. My understanding is that they first estimate the distribution of factors and use that to estimate above model. But how exactly they go about implementing it is what I am not able to fully understand. As I understand there are other ways also to implement the model using Gauss Quadrature and MLE if I am not wrong.</p><p>Can somebody please explain step by step how to computationally implement this model in simpler way in MATLAB?</p><p>Thank You!</p>Madhur Jajoohttp://de.mathworks.com/matlabcentral/profile/authors/6124441-madhur-jajootag:de.mathworks.com,2005:Question/2582422015-11-30T17:06:00Z2015-11-30T17:43:24ZGetting error about recursion limit?<p>I have getting the recursion error upon calling function.</p><p>Maximum recursion limit of 500 reached. Use set(0,'RecursionLimit',N) to change the limit. Be aware that exceeding your
available stack space can crash MATLAB and/or your computer.</p><p>Error in ismemberBismemberBuiltinTypes</p><p>I guess i have some problem while creating function</p><pre class="language-matlab">function image_e=eyeextract(image1)
x=mov.Height;
y=mov.Width;
image1=im2uint8(img);
figure(1),
imshow(image1);
FaceLMmine=FaceLM([ 20 23 26 29],:);
hold on;
plot( FaceLMmine(:,1), FaceLMmine(:,2), 'r*')
%find the distance between center of eyes
left_eye_ct=(FaceLM(23,1)+FaceLM(20,1))/2; %Centre of left eye xaxis
left_eye_yct=(FaceLM(23,2)+FaceLM(20,2))/2; %Centre of left eye yaxis
hold on;plot(left_eye_ct,left_eye_yct,'b*'); %Test plot for left eye check
right_eye_ct=(FaceLM(26,1)+FaceLM(29,1))/2; %Centre of right eye xaxis
right_eye_yct=(FaceLM(26,2)+FaceLM(29,2))/2; %Centre of right eye yaxis
hold on;plot(right_eye_ct,right_eye_yct,'b*');
ED=right_eye_ct-left_eye_ct;
%for left eye
xrm=FaceLM(23,1); %find xr as the x-coordinate of right corner of eye
xlm=FaceLM(20,1); %find xl as the x-coordinate of left corner of eye
yrm=FaceLM(23,2); %find yr as the y-coordinate of right corner of eye
ylm=FaceLM(20,2); %find yl as the y-coordinate of left corner of eye
x1fmr=round(xrm);
y1fmr=round(yrm-0.40*ED);
x2fmr=round(xlm);
y2fmr=round(ylm+0.30*ED);
xroi_fmr=[x1fmr x2fmr x2fmr x1fmr x1fmr]; %x and y exchanged due to interpretation
yroi_fmr=[y2fmr y2fmr y1fmr y1fmr y2fmr]; %x and y exchanged due to interpretation
fmr_roi=uint8(poly2mask(xroi_fmr,yroi_fmr,x,y));
fmr_ext=fmr_roi.*a;
subplot(2,2,1)
image_e1=croppedimage(fmr_ext);
title('left');
imwrite(image,'left_close.png');
% figure,
%for right eyes
xrm1=FaceLM(26,1); %find xr as the x-coordinate of right corner of eye
xlm1=FaceLM(29,1); %find xl as the x-coordinate of left corner of eye
yrm1=FaceLM(26,2); %find yr as the y-coordinate of right corner of eye
ylm1=FaceLM(29,2); %find yl as the y-coordinate of left corner of eye
x3fmr=round(xrm1);
y3fmr=round(yrm1-0.40*ED);
x4fmr=round(xlm1);
y4fmr=round(ylm1+0.30*ED);
xroi_fmr1=[x3fmr x4fmr x4fmr x3fmr x3fmr]; %x and y exchanged due to interpretation
yroi_fmr1=[y4fmr y4fmr y3fmr y3fmr y4fmr]; %x and y exchanged due to interpretation
fmr_roi1=uint8(poly2mask(xroi_fmr1,yroi_fmr1,x,y));
fmr_ext1=fmr_roi1.*a;
subplot(2,2,2)
image_e=croppedimage(fmr_ext1);
title('right')
imwrite(image1,'right.png');
</pre>Usman http://de.mathworks.com/matlabcentral/profile/authors/5603395-usmantag:de.mathworks.com,2005:Question/2582452015-11-30T17:30:25Z2015-11-30T17:30:25ZPlotting simulation results within GUI<p>Hey there. I am faced with a problem and hope to get some advice on how to solve it in here. I am building a GUI with guide. Within this GUI I am running a SIMULINK simulation. I would like to automatically plot the simulation results afterwards. I do have all the scripts I need in order to do this manually without a GUI. Using the manual way everything runs fine. But when I try to achieve the same results within my GUI I do not get the variables (which should be saved within a struct) into the workspace of the callback routine from which I am running the simulation (I am using the sim-command to run the simulation). I tried to enable logging in the scope block, I used "to workspace" blocks and Outports but neither of the things I tried seem to work.
When I am trying to write the results into a variable using results = sim('modelname') an empty variable is returned. So it seems to me that Simulink is writing to another workspace. Using the debugger, I was not able to find the results I was hoping to get in either of the gui workspaces.</p><p>Has anybody an idea on what my problem could be?</p><p>Thanks in advance</p>Matthias Klmnhttp://de.mathworks.com/matlabcentral/profile/authors/5807375-matthias-klmntag:de.mathworks.com,2005:Question/2582442015-11-30T17:29:20Z2015-11-30T17:29:20ZI am trying to implement csma cd using sim events. can anyone tell me, how can i implement binary exponential algorithm in sim events.<p>I am trying to implement csma cd using sim events. can anyone tell me, how can i implement binary exponential algorithm in sim events.</p>ashokhttp://de.mathworks.com/matlabcentral/profile/authors/4993230-ashoktag:de.mathworks.com,2005:Question/2560022015-11-18T20:54:28Z2015-11-30T17:26:43ZMATLAB Database fetch stalls<p>I am using a compiled MATLAB function that utilizes the Database Toolbox. Occasionally, a fetch stalls out such that there is no error, and the database shows that the connection is sleeping (i.e. has not received the query). There are other connections to the database that could be altering the table of the query, but I would imagine that would throw an error. Is there a known issue or fix related to this?</p><p>The program/exe is built using MATLAB R2013b, Database Toolbox 5.0, and MATLAB Compiler 5.0.</p>Jacob Hartmannhttp://de.mathworks.com/matlabcentral/profile/authors/6495397-jacob-hartmanntag:de.mathworks.com,2005:Question/2573402015-11-25T01:31:25Z2015-11-30T17:14:46ZHelp with simple probability calculation (loop?)<p>I have a 2-column matrix that looks like this:</p><pre class="language-matlab">30 1
30 1
30 1
30 1
30 1
29 0
29 1
29 1
28 1
28 1
28 0
28 0
</pre><p>"1" indicates an occurrence and "0" does not. I need to compute a probability for each unique number in column 1. So the answers should be:</p><pre class="language-matlab">30 = 1
29 = .6667
28 = .50
</pre><p>Now, I have the "count_unique" function from the file exchange that counts the unique numbers and identifies how many occurrences there are for each number. Using this, I have tried to write a for loop that computes this problem, but I am stuck in the mud. I'm grateful for any assistance. Happy Thanksgiving.</p>Caryhttp://de.mathworks.com/matlabcentral/profile/authors/5189162-carytag:de.mathworks.com,2005:Question/2582392015-11-30T16:34:57Z2015-11-30T17:09:30Zfit data with x axis already formatted with dateticks() MATLAB<p>I have been at this for hours, i feel like the simple problems take the longest which is annoying. I cannot seem to fit a curve to my data, i've tried fit(), polyval(), and I cannot get them to work. I think the problem is, my x axis is in months, not really numbers so the functions hate me right now. Here is my code:</p><pre class="language-matlab">startDate = datenum('01-01-1985');
endDate = datenum('12-31-1985');
month = linspace(startDate,endDate,12);
waterLevel1985 = [75.2 75.3 75.4 75.6 75.7 75.75 75.6 75.5 75.3 75.25 75.2 75.25];
</pre><pre class="language-matlab">p = polyfit(month,waterLevel1985,4); %error is here apparently...
x = 1:0.5:12;
bestFit = polyval(p,x);
plot(month,waterLevel1985,x,bestFit)
</pre><pre class="language-matlab">ax = gca;
ax.XTick = month;
datetick('x','mmm','keepticks')
When i plot, I get a graph with jan feb mar apr....etc as my x axis, and the water level values for1985 on my y axis. If I just put plot (month, waterlevel1985, 'r+') I don't get a fitted curve to my data (which looks closest to a 4th degree polynomial). Please help me do this, I cannot figure it out!
</pre><p>EDIT: I've even tried putting [1:1:12] in the polyfit function instead of month and it still won't work. I've been fooling around with polyfit and polyval but they won't work for me. I've even tried the following:</p><pre class="language-matlab">startDate = datenum('01-01-1985');
endDate = datenum('12-31-1985');
month = linspace(startDate,endDate,12);
waterLevel1985 = [75.2 75.3 75.4 75.6 75.7 75.75 75.6 75.5 75.3 75.25 75.2 75.25];
</pre><pre class="language-matlab">p = polyfit([1:1:12],waterLevel1985,4);
x = 1:0.5:12;
bestFit = polyval(p,x);
plot(month,waterLevel1985,'r+')
hold on
plot(x, bestFit)
hold off
</pre><pre class="language-matlab">ax = gca;
ax.XTick = month;
datetick('x','mmm','keepticks')
</pre>Damian Connorshttp://de.mathworks.com/matlabcentral/profile/authors/7347205-damian-connorstag:de.mathworks.com,2005:Question/2582332015-11-30T16:00:41Z2015-11-30T16:42:31ZThe most likely point closest to best fit line?<p>So I m using regression to best fit a plot of data. Each data point is represented by distance and value. If the residuals are defined as the error of the points away from the best fit line, I can plot a normal probability density function plot of the likelihood of the residuals. So I have 2 plots. The first plot shows distance(of points, not residual distance) vs value and the second plot shows residuals vs density(normal probability density function). I m trying to find the minimum distance of the points in terms of the first plots x values and at the same time chose the point that has the smallest residual (closest to best fit line) based on the normal probability density function. So I cant just pick the minimum value of the residuals because the data may be different each time. My knowledge of statistics is very limited so i m not sure if this is the best way to find the most likely point that is closest to best fit line. Attached is the code,</p><pre> yVals = zeros(1,10);
yVals(1,1) = 2;
yVals(1,2) = 5;
yVals(1,3) = 6;
yVals(1,4) = 9;
yVals(1,5) = 14;
yVals(1,6) = 18;
yVals(1,7) = 25;
yVals(1,8) = 21;
yVals(1,9) = 23;
yVals(1,10) = 27;</pre><pre> xVals = 1:10;
xVals = xVals';
yVals = yVals/max(yVals);
yVals = yVals'
scatter(xVals, yVals);
hold on;
[logitCoef,dev, stats] = glmfit(xVals,yVals,'binomial','logit');
logitFit = glmval(logitCoef,xVals,'logit');
figure(1);
plot(xVals,logitFit,'g-','MarkerSize', 2 );xlabel('Distance'); ylabel('Value');
legend('logit');</pre><pre> A = stats.resid;
M = mean(A);
S = std(A);
MAX = max(A);
MIN = min(A);
[residuals residualIndex] = sort(stats.resid);
figure(2);
PDF = normpdf(residuals, M, S);
plot(residuals, PDF);xlabel('Residuals'); ylabel('Density');</pre><img src = "/matlabcentral/answers/uploaded_files/41071/plot1.png"><img src = "/matlabcentral/answers/uploaded_files/41072/plot2.png">Ronanhttp://de.mathworks.com/matlabcentral/profile/authors/6028419-ronantag:de.mathworks.com,2005:Question/2582162015-11-30T12:50:21Z2015-11-30T16:33:56ZI am new to Matlab. Can anyone explain how I get this simple prog to run on my mac?<p>%Initialise array</p><p>a=[1 -3 2 5];
try
%Try to display an element
index = input('Enter subscript of element to display: ');
disp[('a(int2str.(index))=(num2str.(a(index)')];
catch
%If we get here an error occurred
disp('Illegal subscript:int2str(index)');
end</p>Robert Boothhttp://de.mathworks.com/matlabcentral/profile/authors/7259752-robert-boothtag:de.mathworks.com,2005:Question/2573902015-11-25T09:17:39Z2015-11-30T16:32:52ZPlot the values between the range<img src = "/matlabcentral/answers/uploaded_files/40770/Capture.JPG"><p>I need to plot the values between the range using the bar plot ?</p><p>for example</p><pre> Bar A 10-15</pre><pre> Bar B 25-30</pre><pre> Bar C 45-50</pre><p>How can i do this ?</p><p>Thanks a lot</p>Gopalakrishnan venkatesanhttp://de.mathworks.com/matlabcentral/profile/authors/4887278-gopalakrishnan-venkatesantag:de.mathworks.com,2005:Question/2582362015-11-30T16:23:14Z2015-11-30T16:31:32Zstandard deviation of same values in a matrix<p>Hello,</p><p>I couldn't find anything which could help me with my problem.</p><p>I have a matrix (n x 2) like shown below:</p><img src = "/matlabcentral/answers/uploaded_files/41065/Frage%20Forum_2.1.PNG"><p>I want to calculate the standard deviation of column 2 for all records which have the same valaue in column 1. So I get this:</p><img src = "/matlabcentral/answers/uploaded_files/41066/Frage%20Forum_2.2.PNG"><p>Is there a smart way to do this? Maybe is several steps?</p><p>Thanks!</p>Fabi Borohttp://de.mathworks.com/matlabcentral/profile/authors/3967784-fabi-borotag:de.mathworks.com,2005:Question/2582002015-11-30T10:52:36Z2015-11-30T16:30:34ZUse step size in surf and imagesc<p>I imported a 20 x 20 matrix from a matlab. I used that matrix to plot surface map and image map using surf() and imagesc() as shown below:</p><pre class="language-matlab">figure;
surf(mmx1,'EdgeColor','None', 'facecolor', 'interp');
view(2);
axis equal;
figure;
imagesc(mmx1);
colormap jet;
</pre><p>Although the size of matrix is 20 x 20, the step size is 0.5 mm and hence in the surface and image maps, the X and Y axis should be 10 mm x 10 mm.</p><p>Can you please help me to define this step size so that I'd get an image with 10 mm in both X- and Y-axes?
Thank you for your help.</p>Parizhttp://de.mathworks.com/matlabcentral/profile/authors/5363246-pariztag:de.mathworks.com,2005:Question/965042012-01-11T20:52:00Z2015-11-30T16:30:03ZHow can I count the occurrences of each element in a vector in MATLAB?<p>I would like to be able to return the count of occurences of each element in a vector.</p><p>For example if I have a vector:</p><pre> x=[10 25 4 10 9 4 4]</pre><p>I expect the result to be</p><pre> y=[2 1 3 2 1 3 3].</pre>MathWorks Support Teamhttp://de.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:de.mathworks.com,2005:Question/2582082015-11-30T12:05:23Z2015-11-30T16:27:42ZPatch function gives crosses when multiple squares attempted<p>Trying to place four squares with patch gradients, code works when only doing one but when trying with multiple it produces X with left and right triangles. Coord order same as when works for single</p><pre class="language-matlab">shapesx=[0 5 5 0;0 5 5 0;5 10.5 10.5 5;5 10.5 10.5 5];
shapesy=[0 0 5 5;5 5 10.5 10.5;0 0 5 5;5 5 10.5 10.5];
shapesc=[0 2.5 5 2.5;2.5 5 7.5 5;2.5 5 7.5 5; 5 7.5 10 7.5];
patch(shapesx,shapesy,shapesc)
</pre>John Goacherhttp://de.mathworks.com/matlabcentral/profile/authors/7094562-john-goachertag:de.mathworks.com,2005:Question/2582382015-11-30T16:27:37Z2015-11-30T16:27:37ZHow to divide a irregular shape into equal size of squares and we wish to have the centre cordinates of those squares.<p>I am a engineering student.
plz help me.</p>amit zarolahttp://de.mathworks.com/matlabcentral/profile/authors/7347154-amit-zarolatag:de.mathworks.com,2005:Question/2582372015-11-30T16:26:18Z2015-11-30T16:26:18ZExcel error has stopped working<p>Hi,</p><p>I have problem, any time I run a matlab code which is try to open an excel file, I get an error: _ * <i>Microsoft Excel error has stopped working</i>*_, and it's affecting the functionality of the Microsoft Excel because all the time I have to select close the program and after it is just opening in a safe mode. If I don't work on Matlab I don't have the issue. Anyone knows how to fix it?</p>Jurley Sosa Camachohttp://de.mathworks.com/matlabcentral/profile/authors/6675683-jurley-sosa-camachotag:de.mathworks.com,2005:Question/2579432015-11-28T11:18:09Z2015-11-30T16:14:02ZHi I am getting the following error: Mex file entry point is missing. Please check the (case-sensitive) spelling of mexFunction (for C MEX-files), or the (case-insensitive) spelling of MEXFUNCTION (for FORTRAN MEX-files). What should I do? Thanks<p>Mex file entry point is missing. Please check the (case-sensitive)
spelling of mexFunction (for C MEX-files), or the (case-insensitive)
spelling of MEXFUNCTION (for FORTRAN MEX-files).</p>Joshuahttp://de.mathworks.com/matlabcentral/profile/authors/5714319-joshuatag:de.mathworks.com,2005:Question/2582192015-11-30T13:41:26Z2015-11-30T16:13:50ZCreate a Matrix with a specific main diagonal <p>I want to create a matrix of all one's with the main diagonal of value n. Where I can change the n value from 50,100,500 etc. I'm struggling with the loop function. Help please</p>Adam Idrissihttp://de.mathworks.com/matlabcentral/profile/authors/5725784-adam-idrissitag:de.mathworks.com,2005:Question/2581772015-11-30T09:12:41Z2015-11-30T16:10:52Zhow to put the image that is sky background in the 3D axes in plot<p>please help me with 'how to put the image of sky to background of 3D axis, in the graph what i have plotted'.</p>emmashttp://de.mathworks.com/matlabcentral/profile/authors/7341678-emmastag:de.mathworks.com,2005:Question/2578502015-11-27T15:57:39Z2015-11-30T16:04:17ZDifferent results for centroids using regionprops and imtool for labeled images<p>Hello there,</p><p>I have found that I have different values for centers of points in an image when I measure it with imtool (so myself) and with regionprops.Centroid (automatic).
Which is kind of troublesome for calculations ...</p><p>More precisely, I have a root image right here :</p><img src = "/matlabcentral/answers/uploaded_files/40948/Image_gauche_00000.jpg"><p>And I want to make it look like this one :</p><img src = "/matlabcentral/answers/uploaded_files/40949/Image_droite_00000.jpg"><p>So I measure with imtool the 8 points around the images then use the function 'fitgeotrans' then 'imwarp'.
It works fine.
The problem is, there is a difference when I use a 'normal' image (like my root) or a labeled image (with bwlabel). The transformation goes well, and with 'imtool' I get the same centers. The difference is when I use 'regionprops.Centroid', THERE I have two totally different values between 'imtool' and 'regionprops.Centroid' for the same image (the transformed, labeled one).</p><p>Can anyone explain to me how can this be ? I precise, there is no difference between the two methods before the transformation. And yes, I need the labeled image.</p><p>For example here are the values I measure for the top left point :</p><p>root image, no transformation, imtool : 115,307</p><p>root image, no transformation, regionprops : 109,302</p><p>labeled image, no transformation, imtool : 115,303</p><p>labeled image, no transformation, regionprops : 109,302</p><p>root image, transformation, imtool : 102,551</p><p>root image, transformation, regionprops : 98,551</p><p>labeled image, transformation, imtool : 98, 555</p><p>labeled image, transformation, regionprops : 326,776</p><p>Thank you for your answer.</p>Robert Duponthttp://de.mathworks.com/matlabcentral/profile/authors/7031216-robert-duponttag:de.mathworks.com,2005:Question/2581932015-11-30T10:04:14Z2015-11-30T16:02:38ZMerging two tables based on time interval<p>I have two tables A and B. A consists of information about glucose measurements, B consists insulin medication settings. I want to couple a glucose measurement to the setting of the insulin perfusor. However the timing is different and there are more medication settings than glucose measurements.</p><p>Table A:</p><p>Patientnumber * MeasureGlucose * Time(using datenum) * TimeNormal</p><p>11112222 * 16,9 * 7.3626e+05 * 26-10-2015 17:57:00</p><p>11112222 * 21,5 * 7.3626e+05 * 26-10-2015 19:47:00</p><p>11112222 * 26,3 * 7.3626e+05 * 26-10-2015 22:09:00</p><p>11112222 * 15,6 * 7.3626e+05 * 26-10-2015 02:29:00</p><p>11112222 * 8,8 * 7.3626e+05 * 26-10-2015 06:10:00</p><p>Table B:</p><p>Patientnumber * PerfusorNovorapidDosisE_u * Time(using datenum) * TimeNormal</p><p>11112222 * 1 * 7.3626e+05 * 26-10-2015 17:44:00</p><p>11112222 * 2 * 7.3626e+05 * 26-10-2015 20:00:00</p><p>11112222 * 4 * 7.3626e+05 * 26-10-2015 22:12:00</p><p>11112222 * 4 * 7.3626e+05 * 27-10-2015 02:07:00</p><p>11112222 * 4 * 7.3626e+05 * 27-10-2015 04:05:00</p><p>11112222 * 4 * 7.3626e+05 * 27-10-2015 06:05:00</p><p>11112222 * 2 * 7.3626e+05 * 27-10-2015 08:10:00</p><p>How can I merge these tables in the following way:</p><p>1. Select time of measurement in table A.</p><p>2. Find a medication setting within 40 minutes after the measurement</p><p>3. If no medication setting available in step 2, use the previous medication setting</p><p>I hope someone can help me with this problem setting.</p>Ivo Kuiperhttp://de.mathworks.com/matlabcentral/profile/authors/6171529-ivo-kuipertag:de.mathworks.com,2005:Question/2582242015-11-30T14:40:03Z2015-11-30T16:02:04ZLocate array element within limits given by another array<p>Probably quite easy but I don't know how to get it...
I would like to find the floor of the position of each of the elements (positive decimal numbers) of one array in another array. In the second array the difference between consecutive elements is 2 always.
For example:
a=[3.45 8.99 10.02]
b=[1.03 3.03 5.03 7.03 9.03 11.03 13.03]
where what I want to get is c=[2 4 5]</p>Danahttp://de.mathworks.com/matlabcentral/profile/authors/5152692-danatag:de.mathworks.com,2005:Question/2580952015-11-29T18:12:20Z2015-11-30T15:57:47Zhow to crop a matrix in matlab?<p>i am getting a matrix as output and its size is[1000*77868] because of having many element, i cant see the matrix. it is displaying like"cannot displays element more than 53866. is there any possibility to see the matrix or how to crop the matrix to[512*4000]??</p>barath santhoshhttp://de.mathworks.com/matlabcentral/profile/authors/6853357-barath-santhoshtag:de.mathworks.com,2005:Question/2582092015-11-30T12:09:20Z2015-11-30T15:55:41ZRemove units from a string<p>Hello all,</p><p>I would like to remove the units (for e.g. seconds) from a string and convert it to double.</p><p>For e.g.:
1.00s to 1.00 or 1.25ns to 1.25</p><p>Is there any simple way to do that?</p><p>Thanks.</p>Vamsihttp://de.mathworks.com/matlabcentral/profile/authors/5476358-vamsitag:de.mathworks.com,2005:Question/2581992015-11-30T10:45:31Z2015-11-30T15:49:00Z3>2>1 returns logical 0?<p>When I run 3>2>1 it returns logical 0 (false). Sorry if its a basic question but I can't understand how this is not true.</p>Cian O'Reganhttp://de.mathworks.com/matlabcentral/profile/authors/7345348-cian-o-regantag:de.mathworks.com,2005:Question/2582322015-11-30T15:45:46Z2015-11-30T15:45:46ZSaving Table to a png File<p>How would you go about saving a table to a .png file format (or any other image format, for that matter)?</p><p>Thank you!</p>Phillip Moranhttp://de.mathworks.com/matlabcentral/profile/authors/6189362-phillip-morantag:de.mathworks.com,2005:Question/2582302015-11-30T15:34:03Z2015-11-30T15:41:10Zplease help me to solve this .??? Undefined function or method 'matlab' for input arguments of type 'char'..... codes are attached ,,,,<pre class="language-matlab">clear all; close all;
clc;
%rng default
randn('seed',0);
fprintf ('Dan Simon with input \n');
duration=40; dt=0.1; %randn('seed',0)
N = duration/dt; measnoise = 1 ;
accelnoise = 0.2; % acceleration noise (feet/sec^2)
</pre><pre class="language-matlab">a = [1 dt; 0 1]; % transition matrix
b = [dt^2/2; dt];% input matrix
c = [1 0];% output matrix
%c = [1 0; 0 1]; % measurement matrix
x = [0; 0]; % initial state vector
%Rd = measnoise^2; % measurement error covariance
%Qd = accelnoise^2 * [dt^4/4 dt^3/2; dt^3/2 dt^2]; % proc noise cov
Rd = 100; Qd = 1;
</pre><pre class="language-matlab">P1 = eye(2); % initial estimation covariance
w = sqrt(Qd) * randn(2,N);
v = sqrt(Rd) * randn(1,N);
xup = x;%update state
Pup = eye(1);% update estimation
%********************************************************************
%% To save data for Approach-Case
pos1 = zeros(1,N); poshat1 = zeros(1,N); poshat2 = zeros(1,N);
pos2 = zeros(1,N); posmeas1 = zeros(1,N); S1 = zeros(1,N);
K_1 = zeros(1,N); K_2 = zeros(1,N); INN = zeros(1,N);
Pre_t = zeros(1,N); Pup_t = zeros(1,N);
</pre><pre class="language-matlab">%*********************************************************************
%% Loss is introduced Here !
%********************************************************************%
for jj = 1: 10*duration,
u = 0.05;
x = a * x + b*u + w(:,jj);
z = c*x + v(:,jj);
posmeas1(jj) = z;
</pre><pre> pos1(jj) = x(1); pos2(jj) = x(2);
x_pred = a*xup + b*u;
P_pred = a * Pup * a' + Qd;
Pre_t(jj) = trace(P_pred);</pre><pre> Inn = z - c* xup;
INN(jj) = Inn;
s = c * P_pred * c' + Rd;
K = P_pred * c' * inv(s);</pre><pre> K_1(jj) = K(1); K_2(jj) = K(2); </pre><pre> poshat1(jj) = xup(1); poshat2(jj) = xup(2);
xup = x_pred + K * Inn;
Pup = (eye(2)-K*c)*P_pred;
Pup_t(jj) = trace(Pup);</pre><pre class="language-matlab">end
%--------------------------------------------------------------
%% To plot Estimation in comaprison with Actual Reading for 2 cases
</pre><pre class="language-matlab">figure; subplot(121); plot(K_1); hold on; plot(K_2,'r');
subplot(122); plot(Pre_t); hold on; plot(Pup_t,'r');grid on;
e1 = abs(pos1)-abs(poshat1);
e2 = abs(pos2)-abs(poshat2);
subplot(211); plot(e1); subplot(212); plot(e2,'b'); grid on;
figure; subplot(211);
plot(posmeas1,'g'); hold on; plot(pos1,'r'); plot(poshat1,'b');
grid on; xlabel('time (msec)'); ylabel('position (meter)');
title('Esitmation of position');
legend('Actual State','Filtered Response','Measured Response')
</pre><pre class="language-matlab">subplot(212)
plot(pos2,'r'); hold on; plot(poshat2,'b'); %plot(posmeas1,'g');
grid on; xlabel('time (msec)'); ylabel('position (meter)');
title('Esitmation of Velocity');
legend('Actual State','Filtered Response','Measured State')
</pre>Engr. Muhammad kamran shereenhttp://de.mathworks.com/matlabcentral/profile/authors/7346340-engr-muhammad-kamran-shereentag:de.mathworks.com,2005:Question/2582292015-11-30T15:29:49Z2015-11-30T15:29:49ZPlease help me solve 2d poisson equation using neumann boundary conditions...<p>Help me solve dz^2/dx^2 + dz^2/dy^2 = -k;</p><p>where z'(0,0) = 0;
z'(n,0) = 0;
z' (0,m) = 10^-15;
z'(n,m) = 10^-15;
k = 10^-8</p>Nazmul Islamhttp://de.mathworks.com/matlabcentral/profile/authors/7341754-nazmul-islamtag:de.mathworks.com,2005:Question/2578752015-11-27T18:41:05Z2015-11-30T15:28:13ZHow can i make Arduino stand alone without powering it via usb & writeDigitalPin() slow response problem<p>i uploaded arduino code but if i unplug the usb and plug it again i just lose my programe how can i slove this
and also writeDigitalPin() function is so slow in response</p>Hytham Taghttp://de.mathworks.com/matlabcentral/profile/authors/5539093-hytham-tagtag:de.mathworks.com,2005:Question/2582282015-11-30T15:26:51Z2015-11-30T15:26:51Zcode for mean radial distance of shape in a binary image.<p>I want to create my own function for labeling and regional properties, please help in coding mean radial distance of shapes in binary images.</p>Muhammad Shoaibhttp://de.mathworks.com/matlabcentral/profile/authors/6619683-muhammad-shoaibtag:de.mathworks.com,2005:Question/2582272015-11-30T15:26:40Z2015-11-30T16:33:02ZHow can I make the origin of the coordinate system of a 3D model the same as an image which locates its the origin point at the upper left? <img src = "/matlabcentral/answers/uploaded_files/41063/Coor_1.png"><p>Hi Sir/Madam,
Please, could you help me to make the origin of the 3D model coordinate system starts from the upper left as same as the image in order to project the model above the image such as the attached photos.</p><p>I will highly appreciate your help.
Thank you.
Kind regards,
Nada</p>Nada Kadhimhttp://de.mathworks.com/matlabcentral/profile/authors/5407251-nada-kadhimtag:de.mathworks.com,2005:Question/1071072013-11-21T21:31:02Z2015-11-30T15:24:53ZCan Matlab give me an analytic solution for transient Heat diffusion?<p>I want an analytic solution to the transient Heat Diffusion equation in cylindrical coordinates. My equation is</p><p>dT/dt = d^2T/dr^2 +1/r dT/dr + d^2T/dz^2</p><p>This problem is cylindrically symmetric, so the theta term is zero.</p><p>Is there a way to solve this in MatLab? My prof tells me MatLab should be able to do this with the symbolic toolkit, but all I can find on it concerns ODEs.</p><p>The boundary conditions for this problem are
T(0,z,t) = g(z), T(r,z,0)=0</p>Joshuahttp://de.mathworks.com/matlabcentral/profile/authors/3979687-joshuatag:de.mathworks.com,2005:Question/2576512015-11-26T12:33:58Z2015-11-30T15:23:07Z Failed to open serial port COM3 to communicate with board Uno.<p>Encounter this error when i tried to connect my arduino board with my matlab :Failed to open serial port COM3 to communicate with board Uno. Make sure there is no other
MATLAB arduino object for this board. For troubleshooting, see Arduino Hardware
Troubleshooting.</p><p>Can anyone solve this?</p>kim poh chiewhttp://de.mathworks.com/matlabcentral/profile/authors/6027024-kim-poh-chiewtag:de.mathworks.com,2005:Question/2580992015-11-29T18:28:24Z2015-11-30T15:20:08Z optimization function in matlab <p>i would like to ask about the optimization in matlab function that works with multi variable input with each input has different boundaries the output is only one variables</p>mohammed husseinhttp://de.mathworks.com/matlabcentral/profile/authors/5824263-mohammed-hussein