http://www.mathworks.nl/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2014-08-29T16:04:58Ztag:www.mathworks.nl,2005:Question/1527832014-08-29T16:04:58Z2014-08-29T16:04:58ZHow can I create code for an embedded Linux target with Simulink hosted on Windows?<p>I want to be able to create code a multitasking embedded Linux target from Simulink hosted on Windows. The Windows machine does not have access to the Linux compiler tools and so all I want is to be able to copy the generated code manually to Eclipse on a different Linux machine and build it there.</p><p>I am basically trying to following the method in this post but with the Linux tools being hosted on a different machine: <a href = "http://www.mathworks.co.uk/matlabcentral/answers/95176-from-my-windows-platform-how-do-i-build-a-model-with-concurrently-executing-sample-times-and-which">http://www.mathworks.co.uk/matlabcentral/answers/95176-from-my-windows-platform-how-do-i-build-a-model-with-concurrently-executing-sample-times-and-which</a></p><p>I have set the System target file to 'idelink_ert.tlc' and then on the Code target tab set the Build Format to 'makefile' and the Build action to 'create_makefile'. However, when I try to build the model the process fails when it seems to try and run the makefile to build the target and can't find the target tools. I want 'create_makefile' to do just that and no more; in fact I don't even need a makefile, I just want the .c and .h files.</p><p>Is there a way to stop the build from 'running' the make file?</p>Mike Bardill/matlabcentral/answers/contributors/841081-mike-bardilltag:www.mathworks.nl,2005:Question/1526422014-08-28T14:00:17Z2014-08-29T16:02:33ZTransformation from spectrum into pulse<p>I have a chirped pulse of the form</p><p>E(t) = exp(-t^2)*cos(-15t+7t^2).</p><p>Which looks like this</p><img src = "/matlabcentral/answers/uploaded_files/17499/Pulse%20orig%20example.jpg"><p>If I transform this pulse into frequency domain analytically, that is manually on a piece of paper I will get the following spectrum:</p><p>E(w) = E1(w) + E2(w),</p><p>where</p><p>E1(w) = exp(-(w-15)^2/200)*exp(-7i(w-15)^2/200)</p><p>E2(w) = exp(-(w+15)^2/200)*exp(-7i(w+15)^2/200)</p><p>Now I want to check if this is really the case using ifft. I give the function to be inverse-transformed by ifft to be the spectrum with mathematical form as written above, after applying ifft to this function I hope I can recover the chirped pulse. Here's the code I write to do this:</p><pre class="language-matlab">Fs = 500;
w = -100:1/Fs:100;
Ew = exp(-(w-15).^2/200).*exp(-7*1i*(w-15).^2/200) + exp(-(w+15).^2/200).*exp(7*1i*(w+15).^2/200); % Spectrum of a chirped pulse.
nfft = 2000000;
Et = ifft(Ew,nfft); Pulse in time domain.
Et = Et(1:nfft);
Et = ifftshift(Et);
</pre><pre class="language-matlab">Et = real(Et);
t = (-nfft/2:(nfft/2-1))*Fs/nfft;
subplot(2,1,1)
plot(w,Ew)
subplot(2,1,2)
plot(t,Et)
</pre><p>And I what I got as the pulse is like this,</p><img src = "/matlabcentral/answers/uploaded_files/17497/Pulse%20example.jpg"><p>Which clearly not the original pulse I started with. Can somebody tell me what the problem was?
I have tried to review my manual calculation and I could find no mistake in it. I omitted some prefactors but that shouldn't pose any effect on the form of the curve.</p><p>Thanks in advance for your help.</p>Imam/matlabcentral/answers/contributors/5330169-imamtag:www.mathworks.nl,2005:Question/1527792014-08-29T15:41:16Z2014-08-29T16:02:33ZUsing a containing subsystem name for signals inside the subsystem<p>I've been scouring the documentation for a way to get signals to automatically use their subsystem name in their names. I realize the the full path will contain the subsystem name but I would like something like:</p><pre> firstPartOfName<%mySubsystemName>secondPartOfName</pre><p>So if the containing subsystem name is "SomeSubsystem" the signal name will be "firstPartOfNameSomeSubSystemsecondPartOfName".</p><p>Is there some nice trick for achieving this?</p>Nicholas/matlabcentral/answers/contributors/2420126-nicholastag:www.mathworks.nl,2005:Question/1527502014-08-29T09:17:09Z2014-08-29T16:02:33ZProblem in Image Segmentation in an image?<p>I am using a code that can segment sclera from an eye image and it works fine for the first image
The code that i use is as follows</p><img src = "/matlabcentral/answers/uploaded_files/17529/2.jpg"><p>but when i input this image it can't give me the result. What should i do?</p><img src = "/matlabcentral/answers/uploaded_files/17530/1%20copy.png">Asif Hasan/matlabcentral/answers/contributors/5287485-asif-hasantag:www.mathworks.nl,2005:Question/1526092014-08-28T07:07:37Z2014-08-29T15:53:09ZHow can I solve uneven illumination issues from an image using low-pass filter<p>Hi all,</p><p>I am new to Matlab. I need to know how can fix uneven illumination issues from an image. I have seen morphological operation but that does not work for my test image. I am sure there are various ways to do that however; I will be very happy if anyone can help me with a code to fix illumination issues especially using low-pass filter for my image. (if anyone can give me other approach rather than low-pass filter that will be appreciable as well).</p><p>...........................................................................</p><p>This is my test image.</p><p>...........................................................................</p><p>.........................................................................</p><p>This is what I am looking for.</p><p>Thank you all.</p>Siam/matlabcentral/answers/contributors/5563540-siamtag:www.mathworks.nl,2005:Question/1518082014-08-21T13:59:34Z2014-08-29T15:50:07ZI Have to detect the nucleus of the cell...anyone provide me a code to detect the nucleus in the celll....<p>My criteria is to detect the contour of the cell and the contour of the nucleus.... i have done detecting the cell contour.... but i cannot detect the contour of the nucleus... i don't which segmentation method suits.... give me some idea...plz
i have atttached the image of celll</p><img src = "/matlabcentral/answers/uploaded_files/17083/1.bmp"><p>thanks in advance.</p>sou/matlabcentral/answers/contributors/5484225-soutag:www.mathworks.nl,2005:Question/1527802014-08-29T15:41:31Z2014-08-29T15:47:45ZHow to compress the image ?<p>for example, I have a 3D image in grayscale, 512X512X300.</p><p>I just want to compress it in X and Y plane.</p><p>I want 4 pixels to combine into one pixel.</p><p>And the value of the combined pixel takes average on that 4 pixels or take its max.</p><p>Can I directly do on 3D image? If not, please tell me how to do it on 2D image.</p><p>Thanks.</p>tabw/matlabcentral/answers/contributors/5464797-tabwtag:www.mathworks.nl,2005:Question/1472632014-08-12T07:37:52Z2014-08-29T15:45:23ZSelective plotting from .csv file<p>Hi,</p><p>I've 2 sets of results from another software. Say Design1 and Design2. In each Design I've a set of X and Y values to plot. For Design1 the length is 1mm and for design2 the length is 2mm.
So now, is it possible, If I type in 1mm it has to select design1 and plot the values under it. I've more than 200 Design results with x and y values under each. So I need to write a program so that If i type in a value, it'll select which design it is and plot the value.</p><p>Could someone pls help a little.</p>Ian/matlabcentral/answers/contributors/5293415-iantag:www.mathworks.nl,2005:Question/1527232014-08-29T06:01:41Z2014-08-29T15:37:52Zlow speed of 'ismember' function<p>hi. in my code there is a for loop like the following:</p><pre class="language-matlab">for i=1:n
N=find(~ismember(Vector1,Vector2))
do something...
end
</pre><p>This loop is repeated several thousand times. 'ismember' function is very slow. So that most of the runtime for 'ismember' function lost. Is there any alternative to this?</p><img src = "/matlabcentral/answers/uploaded_files/17528/Capture.JPG">Ehsan/matlabcentral/answers/contributors/4864191-ehsantag:www.mathworks.nl,2005:Question/1527782014-08-29T15:33:45Z2014-08-29T16:01:56Zintroduction with k-means in matlab<p>Hi,</p><p>I just theoretically read k-means and did an example..</p><p>I had 4, 2d items with their coordinates value, and initially k=2</p><p>like</p><ul><li>item variables</li><li>A (5,3)</li><li>B (-1,1)</li><li>C (1,-2)</li><li>D (-3,-2)</li></ul><p>I calculated their centroids and then by measuring euclidean dist among arbitrary cluster and centroids, after calculation I got two cluster (A) and (B,C,D)</p><p>I am looking at matlab and found kmeans function but how I could implement the following example in matlab, I got messed up..</p><p>any hints for first time concept to implement kmeans using matlab using the following example.</p>tusu/matlabcentral/answers/contributors/3779049-tusutag:www.mathworks.nl,2005:Question/1527542014-08-29T09:55:33Z2014-08-29T15:27:10ZHow to get analytic expression for experimental data?<p>Hello to everyone, I am new here!</p><p>I can't really formulate a single question but rather would like to describe what I have been doing so far. Being a rather unexperienced programmer I would appreciate help not only on the main issue but on anything that can be done better. So feel free to comment!</p><p>I am solving a system of partial differential equations with "pdepe" which works fine. For the calculation of the discrete intermediate steps I provide a function that is based on experimental data. The experimental data is not easily fit by one analytic expression so I am fitting it piecewise like so</p><p>function W = W_of_DeltaF(dF,material)</p><pre class="language-matlab">if nargin < 2
fprintf('You have to declare a material first!\n');
end
</pre><pre class="language-matlab">switch material
case 'APO-Tric'
</pre><pre> dF_sp1 = 21.2179113385874;
dF_sp2 = 127.07205949453;
dF_sp3 = 294.787905198327;
dF_sp4 = 409.01335594804;</pre><pre> dF1 = dF(dF<=dF_sp1);
W_coef=[0.33051,0.031024,0.087042];
W1 = W_coef(1)+W_coef(2)*exp(-W_coef(3)*dF1);
W1 = W1(:);</pre><pre> dF2 = dF(dF>dF_sp1 & dF<=dF_sp2);
W_coef=[0.34346,-0.00138,8.488e-005,-2.7283e-006,4.1173e-008,-2.8788e-01
W_const = 9.9778;
W2 = W_coef(1) ...
+ W_coef(2) * (dF2-W_const).^1 ...
+ W_coef(3) * (dF2-W_const).^2 ...
+ W_coef(4) * (dF2-W_const).^3 ...
+ W_coef(5) * (dF2-W_const).^4 ...
+ W_coef(6) * (dF2-W_const).^5 ...
+ W_coef(7) * (dF2-W_const).^6;
W2 = W2(:);</pre><pre> dF3 = dF(dF>dF_sp2 & dF<=dF_sp3);
W_coef=[-0.78166,0.048418,-0.00079418,6.4215e-006,-2.7697e-008,6.1208e-0
W3 = W_coef(1) ...
+ W_coef(2) * (dF3).^1 ...
+ W_coef(3) * (dF3).^2 ...
+ W_coef(4) * (dF3).^3 ...
+ W_coef(5) * (dF3).^4 ...
+ W_coef(6) * (dF3).^5 ...
+ W_coef(7) * (dF3).^6;
W3 = W3(:);</pre><pre> dF4 = dF(dF>dF_sp3 & dF<=dF_sp4);
W_coef=[1.2677,-0.0044196,3.3883e-006];
W4 = W_coef(1) ...
+ W_coef(2) * (dF4).^1 ...
+ W_coef(3) * (dF4).^2;
W4 = W4(:);</pre><pre> dF5 = dF(dF>dF_sp4);
W_coef=[0.0015397,0.027218,10.426];
W_const = 408.14;
W5 = W_coef(1)+W_coef(2)*exp(-(dF5-W_const)/W_coef(3));
W5 = W5(:);</pre><pre> W = [W1; W2; W3; W4; W5];</pre><pre> case 'some other material'
do this</pre><pre> otherwise
sprintf('Sorry, you did not provide a valid string for "material".\n');
end</pre><p>This has some disadvantages. The intersection of the analytic functions are often not smooth, i.e. differentiable, which might cause problems. Also this piecewise fitting can get quite tedious and time consuming since it has to be repeated and tuned for every new 'material'.</p><p>I thought about doing something like tracing the limited number of experimental data points with something like GIMP to achieve a smooth curve following the data points.</p><p><i>I know this might sound a little unscientific since it creates data where there is no evidence for it, but I can follow certain physical guidelines when tracing the data that are sensible and I need a qualitative behavior rather than the exact shape.</i></p><p>This curve could then be converted back to a larger amount of data points with some sort of plot digitizer. At this point I am still using the data points for piecewise fitting but was thinking that there might be some way of interpolating the points in order to being able to return data between discrete points. I have tried this once briefly but the program became orders of magnitude slower.</p><p>I hope this wasn't too much babble and someone might still be following up to this point. If further input from my side is needed or would be helpful, anytime!</p><p>Until then!</p><p>Cheers!</p>Markus/matlabcentral/answers/contributors/5568440-markustag:www.mathworks.nl,2005:Question/1527752014-08-29T15:26:37Z2014-08-29T15:26:37ZNumber of samples for doing FFT<pre> -2 down vote favorite
</pre><p>I have a set of 10006 samples which resembles 10 period s of a 50 hz signal which is sampled with 50 KHZ.</p><p>as you know the freqeuncy of bins are calculated via SF/N where SF is sampling frequency and N is the number of samples.</p><p>I want to have the magnitudes of the frequency in integer multiples of 5 HZ up to 9 KHZ (for example: 5 , 10 , ..., 1025, 1030...,8000, 80005..9000).</p><p>so if I do the fft with 10006 samples my frequency bins are not any more the integer multiples of 5 and instead they are integer multiples of 50000/10006. and if I truncate my samples then i will have integer multiples of 5 Hz bins but my samples are not any more resembling exactly 10 periods which means I have leakge effec !</p><p>so I am wondering how to have exactlu 5 HZ bins and with out having the spectrum distorted by leakage effect ?!!</p>Ali/matlabcentral/answers/contributors/5068635-alitag:www.mathworks.nl,2005:Question/1527482014-08-29T09:01:20Z2014-08-29T15:20:48ZConverting "twos complement" - decimal to actual twos complement and back to decimal<p>Hello there</p><p>I've been working on a god damn binary-decimal conversion for at least three hours now so please help me out.</p><p>I imported a very large .csv file where the columns represent 32bit twos complement but are actual decimal values. So the very first element for example is 4.294.721.774 instead of an awful lot of ones and zeros.</p><p>In order to convert this number to the actual real value I tried the following:</p><pre class="language-matlab">% q object for 32bit precision
q = quantizier([32 31]);
</pre><pre class="language-matlab">% test with first element
num = 4294721774;
bin = de2bi(num, 'left-msb');
% convert binary array to string
str_bin = mat2str(bin);
</pre><pre class="language-matlab">% cut lead, tail and spaces
str_bin = str_bin(2:end-1);
str_bin = strrep(str_bin, ' ', '');
</pre><pre class="language-matlab">% convert back
output = bin2num(q, str_bin);
</pre><p>But not only is this highly inefficient, it also doesn't work...
Any suggestions?</p>Vinci/matlabcentral/answers/contributors/4751239-vincitag:www.mathworks.nl,2005:Question/1522652014-08-25T14:03:19Z2014-08-29T15:15:26ZUse mex files in matlab for MAC<p>I need to use a function designed to provide ARMA-Garch-in-Mean estimation in matlab and I found a code online in a mex file. Thing is I don't know what to do next in order to use this function in matlab. I am a mac user and don't even know how to set mex files in matlab for mac. So, pretty much I need to do a ARMA-Garch-in-Mean estimation and have no clue on how to do it.</p><p>Can anyone help? What should I do?</p><p>I can give you de code or the link where I found it if it helps...</p><p>Thanks in advance,
Rui</p>Rui Ascenso/matlabcentral/answers/contributors/5549067-rui-ascensotag:www.mathworks.nl,2005:Question/1527582014-08-29T10:44:16Z2014-08-29T15:06:14ZHow Do I free up a Fortran Mexed substructure (running out of memory-leaking memory)<p>I have a program inwhich matlab is calling a mexed Fortran 77 subroutine. Created in the mexed fortran file is a structure within structure for output. So I create these temporary structures that creates the main output structure.. So that all works fine......... Now its a matter of RELEASING these temporary subs structures because after the program gets called a few 1000 times, I get the low-memory notice, then soon matlab crashes and burns. I had the task manager showing me that the PF usuage does not drop back down after each call.</p><p>The temporary structures being created are using:
tmpstruct = mxCreateStructMatrix(x,x,x,x)</p><p>I have tried at the end of the fortran file before it returns to matlab the following:
mxfree(tmpstruct) and mxDestroyArray(tmpstruct) and the memory never never gets released
until I shut down matlab or the memory leak shuts down matlab.</p><p>Any ideas ????</p>Rick/matlabcentral/answers/contributors/3396325-ricktag:www.mathworks.nl,2005:Question/563992012-12-12T13:21:04Z2014-08-29T15:01:07ZSimulink: Bus to Vector<p>I need to convert a vector to a bus signal using an already specified bus object.</p><p>Simulink has a bus to vector block but there seems to be no way of doing the opposite.</p><p>I'd appreciate any ideas.</p>Tolutola/matlabcentral/answers/contributors/3739101-tolutolatag:www.mathworks.nl,2005:Question/1527702014-08-29T14:37:47Z2014-08-29T14:56:32Zhow can i create background black in rgb image?<p>i need to segment the cervical cell image...i decided to segment using watershed segmentation algorithm...in this segmentation types i have to separate cell nuclei from cytoplasm...i tried many types but i could not get output
my coding and images are given</p><p>clc;
clear all;
close all;
he=imread('E:\ME project\pap smear image.jpg');
w =imresize(he,[290 290]);
imshow(w);</p><p>h = makecform('srgb2lab');
lab_he = applycform(w,h);</p><p>l = lab_he(:,:,1);
figure, imshow(l), title('l');
% Converting into double %
l= double(lab_he(:,:,2:3));
% % obtaining rows and columns of transformed image %
nrows = size(l,1);
ncols = size(l,2);
% % Reshaping image taking each value column wise %
ab= reshape(l,nrows*ncols,2);
% No of clusters to be created with five iterations %
nColors = 1;
[cluster_idx, cluster_center] = kmeans(ab,nColors,'distance','sqEuclidean','Replicates',1);
% Reshaping and showing the clusters %
pixel_labels = reshape(cluster_idx,nrows,ncols);
imshow(pixel_labels,[]), title('image labeled by cluster index');
% % creating five element array %
segmented_images = cell(1);
% Creating tiles for three different colors %
rgb_label = repmat(pixel_labels,[1 1 3]);
% Assigning clustered objects to array(segmented_image) %
for k = 1:nColors
color = w;
color(rgb_label ~= k) = 0;
segmented_images{k} = color;
end
%displaying different cluster objects %
imshow(segmented_images{1}), title('objects in cluster 1');</p><pre> % Evaluating mean of all cluster centers %
mean_cluster_value = mean(cluster_center,2);
% Sorting the mean cluster array and storing sorted index in idx %
[tmp, idx] = sort(mean_cluster_value);</pre><pre> n1_cluster_num = idx(1);
l = lab_he(:,:,1);
n1_idx = find(pixel_labels == n1_cluster_num);
L_n1 = l(n1_idx);
is_light_n1 = im2bw(L_n1,graythresh(L_n1));
nuclei_labels = repmat(uint8(0),[nrows ncols]);
nuclei_labels(n1_idx(is_light_n1==false)) = 1;
nuclei_labels = repmat(nuclei_labels,[1 1 3]);
n1_nuclei = w;
n1_nuclei(nuclei_labels ~= 1) = 0;
imshow(n1_nuclei), title('n1 nuclei');</pre><p>h = makecform('srgb2lab');
lab = applycform(n1_nuclei,h);
l1 = lab(:,:,1);
figure, imshow(l1), title('l1');
I3 = imadjust(l1);
hy = fspecial('sobel');
hx = hy';
Iy = imfilter(double(I3), hy, 'replicate');
Ix = imfilter(double(I3), hx, 'replicate');
gradmag = sqrt(Ix.^2 + Iy.^2);
figure, imshow(gradmag,[]), title('Gradient magnitude (gradmag)')</p><p>W = imregionalmax(gradmag);
figure, imshow(W), title('Regional Minima in Original Image');</p><p>L=watershed(gradmag);
wr=L==0;
figure,imshow(wr)</p><p>q=imadjust(gradmag);
d = edge(q,'canny',.19);</p><p>ds = bwareaopen(d,15);</p><p>d1=im2double(l1);
iout= d1;
BW= ds;
iout(:,:,1) = iout; %# Initialize red color plane
iout(:,:,2) = iout(:,:,1); %# Initialize green color plane
iout(:,:,3) = iout(:,:,1); %# Initialize blue color plane
iout(:,:,1) = min(iout(:,:,1) + BW, 1); %# Add edges to green color plane
iout(:,:,1) = min(iout(:,:,1) + BW, 1); %# Add edges to blue color plane
figure, imshow(iout), title('iout');</p>sobana/matlabcentral/answers/contributors/5512395-sobanatag:www.mathworks.nl,2005:Question/1527612014-08-29T11:39:23Z2014-08-29T14:42:02ZConversion to function_handle from double is not possible.<pre class="language-matlab">t=0:0.01:10;
tou=0:0.01:10;
p0=input('Enter p0 =');
td=input('Enter value of td =');
k=input('Enter value of k=');
w=input('Enter value of w=');
for m=1:length(t)
for n = 1 : length(tou)
if tou(n)< td;
p(n) =p0*(tou(n)/td);
break;
else
p(n)=p0;
end
P=@(tou)p(n)*sin(w*(t-tou));
end
x(t)=(k/w)*quadgk(P,0,t);
end
plot(t, x(t));
</pre>Nabhdeep/matlabcentral/answers/contributors/5540139-nabhdeeptag:www.mathworks.nl,2005:Question/1527462014-08-29T08:43:33Z2014-08-29T14:41:33ZPerformance when creating an array of class objects<p>Hi</p><p>Using Matlab 2010b Service Pack 1.
We are having a performance issue when creating an array of 1000 objects.</p><p>The array is obj.MyClassArray</p><p>The objects are of class</p><pre class="language-matlab">classdef MyClass < handle
</pre><pre class="language-matlab">properties
</pre><pre class="language-matlab"> prop1
prop2
prop3
</pre><pre class="language-matlab"> nameValueContainerMap % a container.Map(name, MySeriesObject)
</pre><pre class="language-matlab">end
</pre><p>The map class is</p><pre class="language-matlab">classdef MySeries < handle
</pre><pre class="language-matlab">properties
</pre><pre> dates
values % a cell containing n doubles</pre><pre class="language-matlab">end
</pre><p>The cell consists of an array of doubles.</p><p>We are pre-allocating memory by initialising obj.MyClassArray with 1000 copies of a fully populated object of MyClass, using repmat.</p><p>However, we are still finding a performance issue.</p><p>Any ideas?</p><p>Thanks</p><p>Marty</p>Marty Stevens/matlabcentral/answers/contributors/4299050-marty-stevenstag:www.mathworks.nl,2005:Question/1527712014-08-29T14:40:20Z2014-08-29T14:40:20Zhow can I fix the insufficient error in fitsread command?<p>I am using this loop to read 57 fits file which are about 4gig.</p><pre class="language-matlab">path='C:\Users\Kianfar\Documents\Thesis\DATA';
files=dir(path);
a=zeros(5,936,936,5,4);
as=zeros(5,936,936);
</pre><pre> for i=3:7
a{i}=fitsread(strcat(path,'\',files(i).name));
for j=1:5
as{i}=as{i}+a{i}(:,:,j,1);
end
end</pre><p>but it says:</p><p>Error using ==> double
Out of memory. Type HELP MEMORY for your options.</p><p>Error in ==> fitsread>readprimary at 161
data = double(data)*bscale+bzero;</p><p>Error in ==> fitsread at 43
data = readprimary(info,raw);</p><ul><li>_how can I fix this error?</li></ul><p>p.s. the code works for 5 data, but not more than that._ *</p>Sepideh/matlabcentral/answers/contributors/5476058-sepidehtag:www.mathworks.nl,2005:Question/1527622014-08-29T11:56:09Z2014-08-29T14:36:56ZMatlab complier for speed<p>Hi,</p><p>I have read the posts that discuss that the complier does not improve speed, and is really for porting applications to other platforms. However, I have seen that some open-source versions of "matlab" such as scilab do use compliers and I believe their code runs faster when complied vs. when not complied.</p><p>So my question is this: why is it that matlab doesn't have a complier just to speed up execution (not for porting), as other languages often do? Is Matlab already optimized in a way such that a compiling process wouldn't add anything?</p><p>I only ask because I am doing some very computationally intensive applications, and want to make sure there isn't some easy way to increase speed that I haven't thought or heard of.</p><p>Thanks.</p><p>Mike</p>Michael/matlabcentral/answers/contributors/5457402-michaeltag:www.mathworks.nl,2005:Question/1527492014-08-29T09:11:12Z2014-08-29T14:36:14ZFilter Design from Weighted coefficient.<p>Hello all,
I want to design a filter to get input signal. For that i have find the coefficent of an inverse of unknown filter and from these coeffiecents i want to design a filetr. But i don't have any clue how to design a filter from given coefficients in matlab.
One way that i know is if i have coefficient of filter, using that i will make a linear equation (i.e FIR equation) and using that i will make filter. But this procedure is too lengthy (i think).
So is there any inbuilt function available in matlab to design a filter using impulse response (coefficient).</p><p>Please help</p>Vijender/matlabcentral/answers/contributors/4547114-vijendertag:www.mathworks.nl,2005:Question/1526852014-08-28T20:47:46Z2014-08-29T14:31:04ZFIND requires variable sizing<p>i am facing a problem of "Find requires variable sizing" whenever i compile my matlab function block of simevents. the scenario is simple that is i have to fimd the indexes from an array using find function:
min_loc = find(pat_w_time(:,k)==min(pat_w_time(:,k)));</p><p>i have tried to google it a lot and also tried to search mathworks but all in vain
moreover i have also tried code.varsize and emel.varsize but agian i am getting error.
help appreciated</p>Idrees Idrees/matlabcentral/answers/contributors/5554187-idrees-idreestag:www.mathworks.nl,2005:Question/1417462014-07-14T11:10:41Z2014-08-29T14:26:50ZSolve symbolic system of equations when specifying solutions<p>Probably not the best question title, but didn't come to think of a better description.</p><p>Is it possible to let Matlab solve a system of equations for the case where I want to use a specific definition on some of the solutions?</p><p>E.g. for a 2-by-2 system <b>Ax</b> = <b>b</b> I can, by hand, derive b1/x1 = a11+(a12*a21)/((Z2)-a22) with Z2=b2/x2 and b2/x2 = a22+(a12*a21)/((Z1)-a11) with Z1=b1/x1 (ignore that I'm going in a circle, I just need to find expressions for bm/xm when specifying the ratio bn/xn for all <i>n</i> different from <i>m</i>)</p><p>Ideally I'd like to use Matlab to do this for a 3-by-3 system as the algebra becomes a bit hairy. As I don't have so much experience with the symbolic tool box I thought I'd try with a 2-by-2 system to begin with as it should be easier, but so far I haven't managed to get the correct results.</p><p>Any inputs are greatly appreciated.</p>dm/matlabcentral/answers/contributors/1555892-dmtag:www.mathworks.nl,2005:Question/1286132014-05-07T02:50:52Z2014-08-29T14:22:39ZHow can I correct this error in LOOKTIF of COMSTAT program? I cannot proceed with thresholding and COMSTAT analysis because of this error.<p>The program found 8 tif files in the current directory /Users/sanchezzoe/Desktop/C48A1GFP
All the images are listed above.</p><p>Enter number of the image you want to view > 3
??? Undefined function or method 'display_images_func' for input arguments of type 'uint8'.</p><p>Error in ==> looktif at 120
display_images_func(bb,'gray', 's', [filename, ' - Original']);</p>Zoe/matlabcentral/answers/contributors/2191810-zoetag:www.mathworks.nl,2005:Question/1527572014-08-29T10:31:06Z2014-08-29T14:20:36ZPlotting a a constant line in a graph<p>Hi all,</p><p>I need for plotting a constant line in a chart in which there is a time series X.
So, given the time series X, texting in the command window the code:</p><pre class="language-matlab">plot(X)
</pre><p>I get the time series plot.
How can I add to the graph a constant line k = 2?
Thanks for help.</p>Quantopic/matlabcentral/answers/contributors/4281759-quantopictag:www.mathworks.nl,2005:Question/1418532014-07-15T02:08:44Z2014-08-29T14:18:06ZFind degree of non-polynomial expression in Matlab<p>Hi,</p><p>say i have an expression as such:</p><pre class="language-matlab">syms x
y = x^(-5/2)
</pre><p>how to find the exponent of x since y is not a polynomial. is it possible?</p><p>thanks</p>Arvind Rajan/matlabcentral/answers/contributors/5248405-arvind-rajantag:www.mathworks.nl,2005:Question/1527672014-08-29T12:40:35Z2014-08-29T14:01:24Zxcorr and time lag<p>Hi all,</p><p>I have a simple, but yet I can't seem to figure it out, question about crosscorrelation.When I find my maximum crosscorrelation, I want to find the corresponding time lag.
What I have in code so far:</p><pre class="language-matlab">x = [0 0 1 5 1 -2 -3 -2 0 0];
y = [0 0 1 5 1 -2 -3 -2 0 0];
X2 = xcorr(x,y,'coeff'); (so we expect a xcorr of 1 because its the same signal)
plot(lags,C)
[val,idx] = max(abs(C))
</pre><p>Now it says that the maximum crosscorrelation (1) is at time lag 10. now I get that because the time series goes from -9 till +9, so step 10 is at zero-lag, but how can I get as answer the zero and not 10. So I want the real value of time lag and not the amount of steps.</p><p>Later on I would actually want to make the time lags correspond to real time as well ,so for example a lag of 1 equals to 2 seconds, which is the reason I want the amount and not the steps so I know how many seconds really passed. How can I do this also, so make the time lag correspond to real seconds?</p>N/matlabcentral/answers/contributors/4790141-ntag:www.mathworks.nl,2005:Question/1421212014-07-16T18:51:57Z2014-08-29T13:58:29ZError in mupadmex eval function<p>So I'm trying to do circuit evaluation. Sometimes it evaluates fine and I get solved variables, but often I get the following error:</p><pre class="language-matlab">Error using mupadmex
Error in MuPAD command: Cannot define a matrix over 'Dom::ExpressionField()'.
[(Dom::Matrix(Dom::ExpressionField()))::new]
</pre><pre class="language-matlab">Error in sym/subsref (line 687)
B = mupadmex('symobj::subsref',A.s,inds{:});
</pre><pre class="language-matlab">Error in CircuitGA (line 327)
eval([char(X(i)) '=' char(V(i)) ';']);
</pre><p>Does anyone know why this is happening? Is there a fix?</p>Madeleine Fort/matlabcentral/answers/contributors/5012338-madeleine-forttag:www.mathworks.nl,2005:Question/1527222014-08-29T05:55:27Z2014-08-29T13:46:53ZStopping criterion in GA<p>hi everyone
I have written a genetic algorithm in matlab and I need to define a stop criterion in which :</p><p>if after 100 iteration the produced answer is the same as previous answers, the algorithm must be stopped</p><p>how can I write this?
can someone help?</p>alexaa1989/matlabcentral/answers/contributors/5511789-alexaa1989tag:www.mathworks.nl,2005:Question/1527392014-08-29T07:50:53Z2014-08-29T13:36:57ZHow to put names of columns with the "To File" block using the "Timeseries" format ?<p>Hi,</p><p>I would like to save the result of my simulink model with a "To File" block but moreover having the different names of these data at the first line.</p><p>- How can I do that ?
- Is it possible to recover the name (the goto tag) from a "From block" ?</p><p>Thanks a lot</p>Fra/matlabcentral/answers/contributors/3743730-fratag:www.mathworks.nl,2005:Question/1527062014-08-29T00:18:47Z2014-08-29T13:34:41Zfind intersection between matrix and draw line on a figure<p>Dear all,</p><p>I have a 360X300 matrix that represent fluorescent intensities along the line. Each cell in a column (1:360), has a certain intensity value that changes in time (rows 1:300). The fluorescent signal is slightly moving through time, so at time 0 is in column e.g., 2, than in time point 2, it is in column 5, etc.
I would like to draw the line on top of the figure tracing the position of the signal at each time frame, so get the information about the position of the signal at each time frame, i.e.
time1 - position 5
time2 - position 7
time3 - position 9, etc.</p><p>The signal is noisy so it has to be done manually, this way, no peak finding or similar. I used imfreehand but is gives me information about XY coordinates and not the exact [row column].</p><p>Thanks in advance,
jakub</p>Jakub/matlabcentral/answers/contributors/3118730-jakubtag:www.mathworks.nl,2005:Question/1441662014-07-31T03:30:31Z2014-08-29T13:33:37ZComparing accuracy of symbolic computation with matlabFunction<p>Hi,</p><p>I have an expression called as DCritn (dynamically generated based on user input) which has 2 parameters and 2 decision variables.</p><p>I'm trying to minimize this expression using fmincon for different combinations of parameters (and different start points)</p><p>I have created a handle for the expression using matlabFunction and it works fine (well for most part).</p><p>For certain combination of parameters and start points, the function handle evaluation does not match the symbolic evaluation of the same expression by using double(subs(expression)). Why? Which is more correct?</p><pre class="language-matlab">%Generating the list of decision/explanatory variables;
</pre><pre class="language-matlab">t1 = sym(zeros(1, 2));
</pre><pre class="language-matlab">for k=1:2
</pre><pre> t1(k) = sym(sprintf('x%d', k));</pre><pre class="language-matlab">end
</pre><pre class="language-matlab">%Generating the list of parameters;
</pre><pre class="language-matlab">q = sym(zeros(1, 2));
</pre><pre class="language-matlab">for k=1:2
</pre><pre> q(k) = sym(sprintf('q%d', k));</pre><pre class="language-matlab">end
</pre><pre> %Below is the value for expression/objective function DCritn. Since it is dynamically generated so providing here an example;
%Note, for below example, "simplify" function could be used to make it shorter. Consciously not using it, as in my real-life example I might have 6 or even 10 decision variables with even longer expressions for which "simplify" takes forever to run and never able to shorten it;</pre><pre> DCritn = ((q1 - q2)^4*(q1^2*exp(2*q1*x1)*exp(2*q1*x2)*exp(2*q2*x1)*exp(2*q2*x2) + q2^2*exp(2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2^2*exp(q1*x1)*exp(q1*x2)*exp(q2*x1)*exp(q2*x2) - 2*q1^2*q2^2*x1^2*x2^2*exp(q1*x1)*exp(q1*x2)*exp(q2*x1)*exp(q2*x2) + 2*q1*q2^2*x1*x2^2*exp(q1*x1)*exp(q1*x2)*exp(q2*x1)*exp(q2*x2) + 2*q1*q2^2*x1^2*x2*exp(q1*x1)*exp(q1*x2)*exp(q2*x1)*exp(q2*x2) - 4*q1^2*q2*x1*x2^2*exp(q1*x1)*exp(q1*x2)*exp(q2*x1)*exp(q2*x2) - 4*q1^2*q2*x1^2*x2*exp(q1*x1)*exp(q1*x2)*exp(q2*x1)*exp(q2*x2) - 4*q1*q2*x1*x2*exp(q1*x1)*exp(q1*x2)*exp(q2*x1)*exp(q2*x2)));</pre><pre class="language-matlab">%Evaluating gradient of objective function for supplying to fmincon;
</pre><pre class="language-matlab">DCritnGrad= jacobian(DCritn ,t1).';
</pre><pre class="language-matlab">%Defining matlab function handle for objective func;
</pre><pre class="language-matlab">DCritnF = matlabFunction(DCritn,'vars',{t1.',q.'},'file',FileNmForDCritn);
</pre><pre class="language-matlab">%Defining matlab function handles for objective func and gradient together;
%This will be useful when fmincon needs both and saves time in evaluating them
%independently;
</pre><pre class="language-matlab">DCritnObjFObjGradF = matlabFunction(DCritn,DCritnGrad,'vars',{t1.',q.'},'file',FileNmForDCritnObj_Grad);
</pre><p>Now I try to evaluate the value of DCritn in three different ways. As seen below the answers don't match. The differences might seem less but since I'm running fmincon for many different parameter combinations and different start points, wrong results get returned for considerable instances.</p><p>>> DCritnF([.0001,85].',[0.24875,0.07].')</p><p>ans =</p><pre> 1.206125170348200e+09</pre><p>>> DCritnObjFObjGradF([.0001,85].',[0.24875,0.07].')</p><p>ans =</p><pre> 1.206125876160960e+09</pre><p>>> double(subs(DCritn,[t1,q],{[.0001,85,0.24875,0.07]}))</p><p>ans =</p><pre> 1.206125421571699e+09</pre><p>The problem is acute as for some start points the fmincon stops with 1 iteration with exitflag -3. On the other hand if I had simplified DCritn using "simplify" function and then fed to matlabFunction and then run fmincon with same start point as before it terminates with exitflag 1 which is good.</p><p>So I guess it comes down to accuracy of function evaluation.</p>Hari/matlabcentral/answers/contributors/4996260-haritag:www.mathworks.nl,2005:Question/1472812014-08-12T09:36:28Z2014-08-29T13:31:01ZmexPrintf no longer works in r2014a?<p>mexPrintf() seems to have stopped working entirely in r2014a?</p><p>I have several fully-inlined C MEX S functions, which need to open up work vectors for signal buffers. To keep an eye on them, I have code in the .c file which ways something like:</p><p>mexPrintf("Initialised a buffer of %d samples.\n", *MaxDelaySamples+1);</p><p>I always used to see a stream of these messages pop up in my command window when running a model, or when creating new RTW code from the model code.</p><p>Under r2014a, however, the messages don't appear at all? I didn't change anything in my code which should affect this, so far as I am aware. Any ideas?</p>Andrew Roscoe/matlabcentral/answers/contributors/391499-andrew-roscoetag:www.mathworks.nl,2005:Question/1527562014-08-29T10:08:16Z2014-08-29T13:28:03Zfind the dependence ratio<img src = "/matlabcentral/answers/uploaded_files/17539/3.png"><p>hi,
i have a graph above. Now i want to comment in this graph. For example, if the channels increase 4 times, the OSNR decrease 'x' times.
What function should i use to find 'x'?</p>son/matlabcentral/answers/contributors/5212026-sontag:www.mathworks.nl,2005:Question/1522812014-08-25T15:56:35Z2014-08-29T13:25:14ZCalculate the distance between two objects automatically using matlab. <p>hi there!</p><p>i am currently doing project on image processing in matlab, in which I'm assigned to calculate the Euclidean distance between two object automatically.here is the image link <a href = "https://imageshack.com/i/pcUJ9tQgj">https://imageshack.com/i/pcUJ9tQgj</a> i first converted the image to binary using 'im2bw', then i applied 'canny' edge detection method and obtained the edges, and by using 'find' function i got the corresponding pixel values. And i am not able to processed further, problem is i have to get array of pixel coordinates for object A and object B separately. and the code has to find which pixel coordinates is nearer between both objects and calculate the nearer distance. I'd very much appreciate your input.</p><p>Sincrely,
lakshya</p>Lakshya/matlabcentral/answers/contributors/5534534-lakshyatag:www.mathworks.nl,2005:Question/1462462014-08-04T17:15:07Z2014-08-29T13:24:55Zsimplifying symbolic expressions using assumptions<p>Hi all,</p><p>I have a symbolic equation as follows:</p><p>A = X / (XY + 1);</p><p>I know that for my specific case XY >> 1</p><p>I wish to simplify this equation using this assumption such that the denominator simplifies to 1 + XY ~ XY and A becomes X/XY = 1/Y.</p><p>Are there tools/functions in the symbolic math toolbox that allow one to do these user defined simplifications on a symbolic expression?</p><p>If not then is there a way I can do this through some code?</p><p>Thanks,
Bhupi</p>Bhupi/matlabcentral/answers/contributors/4032669-bhupitag:www.mathworks.nl,2005:Question/1300822014-05-18T18:42:01Z2014-08-29T13:21:40ZNoise Removing of an image matlab Code <p>Hi! Everyone i am new in matlab . I tried many process in matlab but can not get my desire output. Can anyone help me with some code that can remove image noise. The image is bellow. Please give me code to remove noise.. I need only white part and the other part will be black. Any help will be appreciated....... Thanks in advance...</p><img src = "/matlabcentral/answers/uploaded_files/12917/Screenshot%20at%20May%2008%2012-19-46.jpg">Asif Hasan/matlabcentral/answers/contributors/5287485-asif-hasantag:www.mathworks.nl,2005:Question/1527642014-08-29T12:15:27Z2014-08-29T13:19:36ZHow to obtain improfile for shadow and non shadow regions in gray image ?<p>In matlab we have a command called improfile. I want to use it to plot a graph of comparison between shadow and non shadow areas in an gray image... My input image is gray image with shadows on some regions... The Improfile should contain 2 graphs one representing shadow pixles and other non shadow pixles... any help on this...</p>Anand/matlabcentral/answers/contributors/5407281-anandtag:www.mathworks.nl,2005:Question/1527602014-08-29T11:32:03Z2014-08-29T13:18:50ZFFT-based convolution by Bruno Luong <p>I downloaded the code and tried to install launching the installation function from Matlab command line. But I got the following error that I am copying in the following.
I verified that clang is installed on my Mac running Maverick 10.9.4
f4230:~ mauede$ which clang
/usr/bin/clang</p><p>I would greatly appreciate your help.
Thank you so much.
Regards,
Maura Monville</p><pre class="language-matlab">>> convnfft_install
-> mexopts.sh sourced from directory (DIR = $MATLAB/bin)
FILE = /Applications/MATLAB_R2013b.app/bin/mexopts.sh
----------------------------------------------------------------
-> MATLAB = /Applications/MATLAB_R2013b.app
-> CC = xcrun -sdk macosx10.7 clang
-> CC flags:
CFLAGS = -fno-common -arch x86_64 -isysroot -mmacosx-version-min=10.7 -fexceptions
CDEBUGFLAGS = -g
COPTIMFLAGS = -O2 -DNDEBUG
CLIBS = -L/Applications/MATLAB_R2013b.app/bin/maci64 -lmx -lmex -lmat -lstdc++
arguments =
-> CXX = xcrun -sdk macosx10.7 clang++
-> CXX flags:
CXXFLAGS = -fno-common -fexceptions -arch x86_64 -isysroot -mmacosx-version-min=10.7
CXXDEBUGFLAGS = -g
CXXOPTIMFLAGS = -O2 -DNDEBUG
CXXLIBS = -L/Applications/MATLAB_R2013b.app/bin/maci64 -lmx -lmex -lmat -lstdc++
arguments =
-> FC = gfortran
-> FC flags:
FFLAGS = -fexceptions -m64 -fbackslash
FDEBUGFLAGS = -g
FOPTIMFLAGS = -O
FLIBS = -L/Applications/MATLAB_R2013b.app/bin/maci64 -lmx -lmex -lmat -L -lgfortran -L -lgfortranbegin
arguments =
-> LD = xcrun -sdk macosx10.7 clang
-> Link flags:
LDFLAGS = -arch x86_64 -Wl,-syslibroot, -mmacosx-version-min=10.7 -bundle -Wl,-exported_symbols_list,/Applications/MATLAB_R2013b.app/extern/lib/maci64/mexFunction.map
LDDEBUGFLAGS = -g
LDOPTIMFLAGS = -O
LDEXTENSION = .mexmaci64
arguments =
-> LDCXX =
-> Link flags:
LDCXXFLAGS =
LDCXXDEBUGFLAGS =
LDCXXOPTIMFLAGS =
LDCXXEXTENSION =
arguments =
----------------------------------------------------------------
</pre><pre class="language-matlab">-> xcrun -sdk macosx10.7 clang -c -I/Applications/MATLAB_R2013b.app/extern/include -I/Applications/MATLAB_R2013b.app/simulink/include -DMATLAB_MEX_FILE -fno-common -arch x86_64 -isysroot -mmacosx-version-min=10.7 -fexceptions -O2 -DNDEBUG "inplaceprod.c"
</pre><pre class="language-matlab">xcodebuild: error: SDK "macosx10.7" cannot be located.
xcrun: error: unable to find utility "clang", not a developer tool or in PATH
</pre><pre> mex: compile of ' "inplaceprod.c"' failed.</pre><pre class="language-matlab">Unable to complete successfully.
</pre><pre class="language-matlab">Error in convnfft_install (line 17)
mex(mexopts{:},'inplaceprod.c');
</pre>Maura Monville/matlabcentral/answers/contributors/5012317-maura-monvilletag:www.mathworks.nl,2005:Question/1516832014-08-20T15:47:38Z2014-08-29T13:17:11Zsolving a cubic equation<p>I am using the command</p><p>x = solve('a*x^3 + b*x^2 + c*x + d')</p><p>to get the polynomial's roots. It returns a symbolic answer. Then i evaluate the a,b,c,d and i do copy-paste the first symbolic answer and then "enter" to get a numerical answer.</p><p>The numbers i get (1 almost real and 2 complex, as it is expected) are not roots of the equation!</p><p>I am looking for the poles of a mechanical system, so the roots must exist... What am i doing wrong?</p>vaggelis vaggelakis/matlabcentral/answers/contributors/3434002-vaggelis-vaggelakistag:www.mathworks.nl,2005:Question/1525382014-08-27T16:32:50Z2014-08-29T13:16:12ZCan anyone please tell me why I am getting this error?<p>A =</p><pre> 2 4 1
3 1 4
5 6 0</pre><p>>> A=finverse(A)
Undefined function 'finverse' for input arguments of type 'double'.</p><p>>></p>Segun/matlabcentral/answers/contributors/5515862-seguntag:www.mathworks.nl,2005:Question/1521182014-08-24T02:06:23Z2014-08-29T13:15:02ZUsing subs for multiple substitution when the symbolic expression is a matrix<p>Hi,</p><p>I have an expression DesignMatrixMult which is 2*2 matrix (in general it will be a n*n matrix). The expression is in terms of four symbolic variables q1/q2/x1/x2.</p><pre class="language-matlab">DesignMatrixMult = [ ((q1*(exp(-q1*x1) - exp(-q2*x1)))/(q1 - q2)^2 - (exp(-q1*x1) - exp(-q2*x1))/(q1 - q2) + (q1*x1*exp(-q1*x1))/(q1 - q2))^2 + ((q1*(exp(-q1*x2) - exp(-q2*x2)))/(q1 - q2)^2 - (exp(-q1*x2) - exp(-q2*x2))/(q1 - q2) + (q1*x2*exp(-q1*x2))/(q1 - q2))^2, - ((q1*(exp(-q1*x1) - exp(-q2*x1)))/(q1 - q2)^2 + (q1*x1*exp(-q2*x1))/(q1 - q2))*((q1*(exp(-q1*x1) - exp(-q2*x1)))/(q1 - q2)^2 - (exp(-q1*x1) - exp(-q2*x1))/(q1 - q2) + (q1*x1*exp(-q1*x1))/(q1 - q2)) - ((q1*(exp(-q1*x2) - exp(-q2*x2)))/(q1 - q2)^2 + (q1*x2*exp(-q2*x2))/(q1 - q2))*((q1*(exp(-q1*x2) - exp(-q2*x2)))/(q1 - q2)^2 - (exp(-q1*x2) - exp(-q2*x2))/(q1 - q2) + (q1*x2*exp(-q1*x2))/(q1 - q2))]
[ - ((q1*(exp(-q1*x1) - exp(-q2*x1)))/(q1 - q2)^2 + (q1*x1*exp(-q2*x1))/(q1 - q2))*((q1*(exp(-q1*x1) - exp(-q2*x1)))/(q1 - q2)^2 - (exp(-q1*x1) - exp(-q2*x1))/(q1 - q2) + (q1*x1*exp(-q1*x1))/(q1 - q2)) - ((q1*(exp(-q1*x2) - exp(-q2*x2)))/(q1 - q2)^2 + (q1*x2*exp(-q2*x2))/(q1 - q2))*((q1*(exp(-q1*x2) - exp(-q2*x2)))/(q1 - q2)^2 - (exp(-q1*x2) - exp(-q2*x2))/(q1 - q2) + (q1*x2*exp(-q1*x2))/(q1 - q2)), ((q1*(exp(-q1*x1) - exp(-q2*x1)))/(q1 - q2)^2 + (q1*x1*exp(-q2*x1))/(q1 - q2))^2 + ((q1*(exp(-q1*x2) - exp(-q2*x2)))/(q1 - q2)^2 + (q1*x2*exp(-q2*x2))/(q1 - q2))^2]
</pre><p>I want to evaluate RANK of the DesignMatrixMult for specific values of the four symbolic variables. I use SUBS function on DesignMatrixMult, then use DOUBLE followed by RANK and this whole process takes ~0.016 second per evaluation (average by checking on a FOR loop run 10^4 times) but this is not good enough as I need to do this evaluation 10^8 times. I want to understand ways to speed up the evaluation process while retaining the accuracy afforded by symbolic approach.</p><p>I thought by doing multiple evaluations together the process will be faster so tried various ways (see below) but not any headway till now.</p><pre class="language-matlab">% METHOD 1 - Using <http://www.mathworks.com/help/symbolic/subs.html SUBS> with "Multiple Scalar Expansion"
</pre><pre class="language-matlab">%Note, dataset C contains the necessary values for the 4 symbolic variables. q1/q2 lies between 0 and 1, while x1/x2 lies between 0 and 500
</pre><pre class="language-matlab">EvalRankDesignMatrixMultMethod1 = rank(double(vpa(subs(DesignMatrixMult,{t1(1),t1(2),q(1),q(2)},{C.z26,C.z27,C.z21,C.z22}))));
</pre><p>But the above approach gives wrong answers. Specifically, DesignMatrixMult is a 2*2 matrix and in the output the rows corresponding to 10^8 instances are not arranged in correct order and subsequent rank is incorrect.</p><p>How to make the above subs approach work?</p><pre class="language-matlab">% METHOD 2 - Using cellfun approach on entire set of 10^8 rows
</pre><pre class="language-matlab">%Create a symbolic function corresponding to DesignMatrixMult.
DesignMatrixMultF = symfun(DesignMatrixMult,[t1 q]);
</pre><pre class="language-matlab">%Create an anonymous function to calculate rank of DesignMatrixMultF.
RankDesignMatrixMultF = @(xsub1,xsub2,qsub1,qsub2)rank(double(DesignMatrixMultF(xsub1,xsub2,qsub1,qsub2)));
</pre><pre class="language-matlab">%Evalauting rank for all the 10^8 combinations in one go
EvalRankDesignMatrixMultMethod2=cell2mat(cellfun(RankDesignMatrixMultF,num2cell(double(C.z26)),num2cell(double(C.z27)),num2cell(double(C.z21)),num2cell(double(C.z22)),'UniformOutput',false));
</pre><p>The above code starts executing but after a couple of minutes it issues an out of memory error and my computer had to be restarted.</p><pre class="language-matlab">% METHOD 3 - Using cellfun approach on chunks of 10^4 rows. Idea is that I will execute these chunks 10^4 times so that out of memory error will not happen.
</pre><pre class="language-matlab">StartCnter = 1;
EndCnter = 10000;
</pre><pre class="language-matlab">%Running the Cellfun in chunks of 10^4
EvalRankDesignMatrixMultMethod3 = cell2mat(cellfun(RankDesignMatrixMultF,num2cell(double(C.z26(StartCnter:EndCnter))),num2cell(double(C.z27(StartCnter:EndCnter))),num2cell(double(C.z21(StartCnter:EndCnter))),num2cell(double(C.z22(StartCnter:EndCnter))),'UniformOutput',false));
</pre><p>The above approach works but takes ~160 seconds..so this means 0.016 seconds per evaluation...so for the complete dataset it will take impractical amount of time. So it seems cellfun approach (even by doing it in chunks) is not a worthy alternative.</p><p>PS: If I had used a matlabFunction approach (no symbolic) then per evaluation takes ~ 6E-5 so 10^8 evaluations wraps in 6000 seconds which is amazing...I understand symbolic can't achieve this peformance but how can I bridge the gap.</p>Hari/matlabcentral/answers/contributors/4996260-haritag:www.mathworks.nl,2005:Question/1525032014-08-27T10:54:42Z2014-08-29T13:04:18Zhow to flip the inputs of an simulink block<p>Hi everyone</p><p>I have an integrator block, and I want to invert its inputs, so I explain</p><p>the first input is x the signal to be integrated (the top input)</p><p>the second input is y the initial condition (the bottom input)</p><p>I want that x became the bottom input and y the top input</p><p>thanks in advance</p>XAXRXTX/matlabcentral/answers/contributors/4836391-xaxrxtxtag:www.mathworks.nl,2005:Question/1527532014-08-29T09:35:25Z2014-08-29T13:00:20ZNET.addAssembly given arithmetic overflow<p>I am using a toolbox that makes use of a NET.addAssembly (developed by DHI namely to read in result files of their software). I am however not familiar with this NET.addAssembly programming and when I adjusted one of their files, I am getting the following error message when I try to read in the result file:</p><pre> MATLAB:NET:CLRException:PropertyGet</pre><pre> Message: Arithmetic operation resulted in an overflow.</pre><p>What can be causing this? The line that is called cannot lead to an overflow as it only contains 123 doubles as a result. I have also been careful to always close the file that I have opened with the close function provided (through an OnClean-up function).</p><p>First the problem only occurred after several calls to my function were made in the same matlab-session and it helped to close matlab and open again. But now I get this error message every time, even after restarting my computer!, so I cannot run my function any more.</p><p>What should I look for in my code?</p>Echidna/matlabcentral/answers/contributors/3447598-echidnatag:www.mathworks.nl,2005:Question/402382012-06-04T14:09:49Z2014-08-29T12:48:24ZSaving Simulink variable to Matlab workspace<p>Hello,</p><p>With the 'to workspace' block i want to write values to the matlab workspace. I load in a value from workspace (from an array i extruded from excel). Each step i want to save this value that i take from the workspace to the variabel A:</p><p>So if it at step 1 in the array the value is 4. I want to write this value of 4 to the variabel A. At step to the value is 10, so i want the 4 to be replace by 10.</p><p>While doing this i experience the following problems.</p><p>The first few steps (4 steps) the variabel a just keeps the value 0 (i set the ammount of date to save to 1 instead of inf as i only need one value). Sometimes i get the correct value. Sometimes i get the value of the step before.</p><p>What am i doing wrong?</p><p>Kind regards,</p><p>Kris</p>Kris/matlabcentral/answers/contributors/3382756-kristag:www.mathworks.nl,2005:Question/1192552014-02-26T20:23:25Z2014-08-29T12:43:19ZDelete duplicate rows from large cell array<p>I have a cell array of the structure 1 x 35 then 1 x 8. This hold data for 35 years and the 8 columns of the 1 x 8 array hold data in various formats eg:</p><pre class="language-matlab">'2000-01-10 1:00' 'HCM' '268' '20' '260' '2345' '0' '90'
</pre><p>However, the data has come with duplicates like this:</p><pre class="language-matlab">'2000-01-10 1:00' 'HCM' '268' '20' '260' '2345' '0' '90'
'2000-01-10 1:00' 'HCM' '268' '20' '260' '2345' '0' '90'
'2000-01-10 2:00' 'HCM' '268' '14' '210' '645' '3' '12'
'2000-01-10 2:00' 'HCM' '268' '14' '210' '645' '3' '12'
'2000-01-10 3:00' 'HCM' '268' '02' '230' '345' '2' '40'
'2000-01-10 3:00' 'HCM' '268' '02' '230' '345' '2' '40'
</pre><p>As chronological order is very important, I would like to remove corresponding duplicate rows (based on the first time col, if my file was name X, the time col would be X{1,1}{1,1}) from each array without changing the order to get something like this:</p><pre class="language-matlab">'2000-01-10 1:00' 'HCM' '268' '20' '260' '2345' '0' '90'
'2000-01-10 2:00' 'HCM' '268' '14' '210' '645' '3' '12'
'2000-01-10 3:00' 'HCM' '268' '02' '230' '345' '2' '40'
</pre><p>Big help if you can help me. I have tried many too may options!</p>Masao Ashtine/matlabcentral/answers/contributors/4739967-masao-ashtinetag:www.mathworks.nl,2005:Question/1527652014-08-29T12:26:33Z2014-08-29T12:39:24ZTo calculate or estimate a center of a convex hull<p>I am trying to find a center or estimated center of a convex hull of a set of points. In Matlab, we can obtain the convex hull of a set points. The coordinates of the points are known. But how can we obtain a relatively precise center of their convex hull? Any idea? Thanks.</p>ZhG/matlabcentral/answers/contributors/2274161-zhgtag:www.mathworks.nl,2005:Question/1527662014-08-29T12:36:23Z2014-08-29T12:36:23ZIs this the correct implementation of the total variation algorithm?<p>I need to compute the total variation of an image based on the algorithm presented <a href = "http://www.math.ucla.edu/~lvese/285j.1.09f/Chambolle.pdf">here</a></p><p>I have implemented the following code using the l1 norm of the spatial fist-order derivatives:</p><pre class="language-matlab">function TV = compute_total_variation1(y)
% y is the image
nbdims = 2;
</pre><pre class="language-matlab">% check number of channels in an image
if size(y,1)==1 || size(y,2)==1
% we have one dimension
nbdims = 1;
end
</pre><pre class="language-matlab">if size(y,1)>1 && size(y,2)>1 && size(y,3)>1
% we have three dimensions
nbdims = 3;
end
</pre><pre class="language-matlab">if nbdims==1
TV = sum(abs(diff(y)));
return;
end
</pre><pre class="language-matlab">% the total variation weight is 1
% weight_tv = ones(size(y));
</pre><pre class="language-matlab">[gx gy] = gradient(y);
% compute using the l1 norm of the first order derivatives
% horizontal
TVgx = sum( abs(gx),nbdims+1);
% vertical
TVgy = sum( abs(gy),nbdims+1);
% TV = TV .* weight_tv;
TV = sum(TVgx(:)) + sum(TVgy(:));
</pre><p>Is the above implementation valid or not?</p>S./matlabcentral/answers/contributors/5129498-stag:www.mathworks.nl,2005:Question/1276742014-04-29T22:33:38Z2014-08-29T12:09:33Z.NET functionality in a compiled script<p>I am using "System.IO.FileSystemWatcher" along with "addlistener" to monitor a directory and then execute a function when a new file appears. This works as intended when the GUI tool is run from Matlab. However, when I compile the tool it no longer works. The compiler does not give any error messages, nor does the tool.</p><p>Is the .NET functionality not available in a compiled matlab tool, or do I need to include something extra when compiling? Any advice is appreciated.</p>Johnathan/matlabcentral/answers/contributors/4224015-johnathan