http://de.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2015-04-19T22:56:26Ztag:de.mathworks.com,2005:Question/2103262015-04-19T10:13:59Z2015-04-19T22:56:26ZMatlab - FFT/PSD Problem for Preemphasis<p>So my plan is the following (create "adaptive" pre/deemp. using Matlab 2015a):</p><ul><li>1. Read an Audiodata ([y,fs]) and generate white Noise with a certain SNR ([n,fs])</li><li></li><li>2. Generate a Filter H which shapes the PSD(y) similiar to the PSD(n)</li><li></li><li>3. Generate an inverse Filter G=H^(-1) which reverts the effect of H.</li><li></li><li>4. Get the output signal</li></ul><p>The code I was thinking to use for this is the following:</p><pre> [y,fs]=audioread('test.wav');
snr=5;
n=awgn(y,snr,'measured')-y;
[pyy,f]=pwelch(y,[],[],length(y)*2-1,fs);
[pnn,fn]=pwelch(n,[],[],length(y)*2-1,fs);</pre><pre> H=sqrt(snr*pnn./pyy);
G=1./H;
outy=ifft(fft(y).*H.*G);
outn=ifft(fft(n).*G);
out=outy+outn;</pre><pre> [pout,fout]=pwelch(outy,[],[],length(outy)*2-1,fs);
[pnout,fnout]=pwelch(outn,[],[],length(outn)*2-1,fs);</pre><p>There are two problems when using the code above:</p><ul><li>1. The pnout should be shaped liked pout (which it isn't).</li><li>2. The outputsignals (outy,outn) are both complex and therefore it is not possible to play the outputfile.</li></ul><p>If I try it another way:</p><pre class="language-matlab">[y,fs]=audioread('test.wav');
snr=5;
n=awgn(y,snr,'measured')-y;
N=length(y);
bin_vals=0:N-1;
fax_Hz= bin_vals*fs/N;
N_2=ceil(N/2);
pyy=(fft(y).*conj(fft(y)));
pnn=(fft(n).*conj(fft(n)));
</pre><pre class="language-matlab">H=sqrt(snr*pnn./pyy);
G=1./H
outy=ifft(fft(y).*H.*G);
outn=ifft(fft(n).*G);
out=outy+outn;
</pre><p>I don't come across the previous problems but in this case I don't use a real PSD but the squared absolute of the frequencydomain-values. (and as I understand it this would give me the power spectrum and not the power spectral density)</p><p>Any ideas why my first way is wrong or how to change my second way to get a real "proper" PSD and not just the PS?</p><p>Thanks!
Klaus</p>klaus eberthttp://de.mathworks.com/matlabcentral/profile/authors/6430383-klaus-eberttag:de.mathworks.com,2005:Question/2102982015-04-19T05:19:42Z2015-04-19T22:48:50ZA(I) = B error. <p>This is what the error says
"In an assignment A(I) = B, the number of
elements in B and I must be the same.</p><p>Error in KF (line 6)
Xhat(i) =zeros(3,1);" How do I solve this.</p><pre> if true
% A = [0.7474 0.453 0.0735; -0.441 -0.06106 0.01205; -0.0723 -0.5735 -0.1334];
B = [0.0421 0.0735 0.01205]';
C = [20 9 1];
U = 0; H = 1;
z = -0.37727 + 0.1*randn(50,1)
Xhat(i) =zeros(3,1);
P = eye(3,3);
Q = 0.00001
R = 0.01
for(i=2:50)
X_(i) = A*Xhat(i-1) + B*U;
P = A*P*A' + Q;
K = P*H'*inv(H*P*H' + Q)
Xhat(i) = X_(i) + K*(z(i)-H*X_(i));
P = (eye(1,1)-K*H)*P;
end
figure
plot([1:50],z,'rs')
hold on
plot([1:50], -0.37727*ones(1,50),'k')
plot([1:50], Xhat,'g')
end</pre>PVRhttp://de.mathworks.com/matlabcentral/profile/authors/5583237-pvrtag:de.mathworks.com,2005:Question/2102702015-04-18T19:34:40Z2015-04-19T22:28:24ZProblems with using mxarrays with the step function in MATLAB Coder<p>I'm trying to convert my image processing code on MATLAB into C by using MATLAB coder. using 'imread' needs a coder.entrinsic declaration. However, this means that the output to imread will be an mxArray. This is a problem as I cannot use this with the step function. The error report from code generation is shown below:</p><img src = "http://puu.sh/hitLD/9b163d691f.png"><p>Does anyone know a way around this? Help will be very much appreciated!</p>Sharan Duggiralahttp://de.mathworks.com/matlabcentral/profile/authors/6290146-sharan-duggiralatag:de.mathworks.com,2005:Question/2104152015-04-19T22:15:06Z2015-04-19T22:15:06Zpiston/con-rod/crank mechanism<p>The crank OA rotates clockwise at a constant angular velocity
of 2000rpm( revolutions per mintune) and the crank angle theta
changes from 10⁰ to 300⁰. OA=0.15m, AB=0.5m.
Im trying to write a Matlab function to calculate the piston
displacement(B)(output argument) for theta(input
argument). Any ideas?</p>george masikovhttp://de.mathworks.com/matlabcentral/profile/authors/6432084-george-masikovtag:de.mathworks.com,2005:Question/2103382015-04-19T11:59:33Z2015-04-19T22:12:22ZHow to include min() in optimization constraint<p>Hi,</p><p>I have an optimization problem for which I want to find a solution using the GlobalSearch solver. I have several constraints of the form "X(20) <= 100 - max([max(X(1:3)) max(X(5:7)) max(X(10:17))])" which I implemented in the "c" argument:
"X(20) - (100 - max([max(X(1:3)) max(X(5:7)) max(X(10:17))]);" (<= 0)</p><p>However, these constraints seem to be ignored by Matlab during optimization. This leads me to suspect that it is not possible to use min() and max() when writing constraints. Is this true? If so, is there a convenient way to implement this without having to write out every single constraint, i.e. "X(20) - (100-X(1)); X(20) - (100-X(2)); etc."?</p><p>Thank you!</p>Greg76http://de.mathworks.com/matlabcentral/profile/authors/6221049-greg76tag:de.mathworks.com,2005:Question/2104132015-04-19T21:18:04Z2015-04-19T22:11:57ZSymbolic variables in R2013a<p>I am currently running Matlab R2013a. I want to use symbolic variables to show how matrices are multiplying together. I know in 2015 there is the 'sym' command. Is there anything like that in 2013?</p>Resen Praytorhttp://de.mathworks.com/matlabcentral/profile/authors/4620157-resen-praytortag:de.mathworks.com,2005:Question/2103962015-04-19T18:59:15Z2015-04-19T22:09:56ZCan some explain why when I tried to display two images side by side it not only didn't display the two images side by side but displayed one image that now had green in it.<p>I used imshowpair(I,B); (what I named the images) and it gave me one of my images with green in it. My only explanation is that the two iamges were folded on each other, but then why the green in it when they were both black and white? Please assist.</p><p>Thank you</p><p>P.S. - Still don't know how to display the images side by side</p>Neohttp://de.mathworks.com/matlabcentral/profile/authors/5733800-neotag:de.mathworks.com,2005:Question/2038312015-04-16T05:27:12Z2015-04-19T21:46:40ZMake a pendulum that moves according to an equation of motion<p>I am trying to make a pendulum in Simulink/ SimMechanics that moves according to the equation of a damped, driven oscillator. I have been able to make the pendulum move but it oscillates for a little and dies down, just to start up again. I put a scope block in and the graph is just simply sinusoidal so I know the motion should not change like it is. I think the issue is that I am applying the force at the bottom of the pendulum (not the joint itself) and the joint is setup for motion under "automatically computed". When I change the joint so its motion is "provided by input" then I get an error that there are to many joints with manual inputs and I should try fixing it by adding joints with auto inputs. When I do that I get the same exact error. I am new to MATLAB so there is a good chance that this is a simple fix but I have no idea. Can someone please help? Thanks!</p><p><<</p><p><<</p><img src = "/matlabcentral/answers/uploaded_files/29155/Screenshot%20(267).png"><p>>></p><p>>></p>Travis Dopphttp://de.mathworks.com/matlabcentral/profile/authors/6152265-travis-dopptag:de.mathworks.com,2005:Question/2104142015-04-19T21:44:37Z2015-04-19T21:48:21ZUse a function in a for lus?<pre> function [ M , g , d ] = evolution
Mycode = [ 0 3 5 4 8 9 8]
M = Kol(Mycode) ;
for i = 1 : 30
[M , d(i)] = update(M)
g(i) = sum(sum(M))
end
end</pre><p>Kol and update are some functions that I made and they work fine when I use them separately but when I try to run the update function in a for loop it gives several errors. Kol generates a big matrix and update should transform the M matrix 30 times.</p>l8moreshttp://de.mathworks.com/matlabcentral/profile/authors/6184673-l8morestag:de.mathworks.com,2005:Question/2103992015-04-19T19:32:11Z2015-04-19T21:34:17Zproblem in storing data in cell<p>I have a loop and the result will be different in the loop.
I want to store the result in a cell. However, only the last part will display in the cell.
here is the result when I run the coding.</p><p>new =</p><pre> [0x512 double]</pre><p>new =</p><pre> []
[143x512 double]</pre><p>new =</p><pre> []
[]
[146x512 double]</pre><p>what is the problem?</p>mirahttp://de.mathworks.com/matlabcentral/profile/authors/4917812-miratag:de.mathworks.com,2005:Question/2104032015-04-19T19:58:09Z2015-04-19T21:26:33ZBlackjack how to define cards as their value<p>Hey everybody,
I am trying to write a very simple blackjack code where the player either hits 21 and wins, or busts and loses. So far i have this,</p><pre class="language-matlab">function card = dealcard;
</pre><pre class="language-matlab">%This program will allow someone to draw a card at random from a full deck
and see what that card would be. you can go through the whole deck
</pre><pre class="language-matlab">persistent dec; %persistent makes it so matlab stores this variable
</pre><pre class="language-matlab">if length(dec)<53
</pre><pre> dec=[1:52]; %one deck of cards</pre><pre> dec=dec(randperm(length(dec))); %this shuffles the cards
end;
card=dec(end);</pre><p>I do not know how to define the cards as being an ace, 2,3,...queen, and king. If anyone could help me with this that would be great.
Thank you.</p>Ryan Bhttp://de.mathworks.com/matlabcentral/profile/authors/6106035-ryan-btag:de.mathworks.com,2005:Question/1952132015-03-30T11:36:26Z2015-04-19T21:21:11Zhow to convert .txt file data to a matrix form<p>I have a text file 'MatK.txt'(extracted from ANSYS as stiffness matrix) which has data as follows:</p><pre class="language-matlab">MATK:
[1,1]: 2.250e+007 [1,3]:-1.688e+007 [1,4]: 1.125e+007
[2,2]: 1.500e+009 [2,5]:-7.500e+008
[3,3]: 3.375e+007 [3,6]: 1.688e+007
[4,4]: 4.500e+007 [4,6]: 1.125e+007
[5,5]: 7.500e+008
[6,6]: 2.250e+007
</pre><p>in which the value inside [ , ] represents row and column number. since it is a symmetric matrix it only shows the upper triangular part. I want the full 6x6 matrix.</p><p>Kindly help me out. Thanks in advance</p>Kamal Berahttp://de.mathworks.com/matlabcentral/profile/authors/6347963-kamal-beratag:de.mathworks.com,2005:Question/2103942015-04-19T18:40:54Z2015-04-19T21:21:00Zhow to divide an image diagonally into two part?<p>i want to divide an image diagonally,into two equal part. how can i do this?</p>Soumyadip Chakrabortyhttp://de.mathworks.com/matlabcentral/profile/authors/6136046-soumyadip-chakrabortytag:de.mathworks.com,2005:Question/2037372015-04-15T19:53:42Z2015-04-19T21:19:32Zlargr txt file to matrix extraction in matlab<p>Hi Mr. Stephen Cobeldick, I am trying to apply your code (see below )to get a matrix of size 1710x1710 from a txt file (attached) as I did earlier to get 6x6 and 18x18 matrices from txt files. Unfortunately it is not working and shows error as</p><pre> Subscripted assignment dimension mismatch.
Error in KSUBmatrix (line 9)
out(k,:) = val{k}(:,2);</pre><p>Kindly help me so that I can apply the code for any matrix dimension I wish to extract.It is urgently required.</p><pre class="language-matlab">str = fileread('STIFFNESS MATRIX .txt'); % txt file name STIFFNESS MATRIX extracted from ANSYS
[tok,idx] = regexp(str,'ROW\s+(\d+)\s+NODE\s+(\d+)\s+[^\n=]+=\s+(\w+)','tokens','end');
tok = vertcat(tok{:});
idx = [1+idx,numel(str)];
fun = @(b,e)reshape(sscanf(str(b:e),'%f'),2,[]).';
val = arrayfun(fun,idx(1:end-1),idx(2:end),'UniformOutput',false);
out = zeros(numel(val));
for k = 1:numel(val)
out(k,:) = val{k}(:,2);
end
K=out; % required structural stiffness matrix
</pre><p>The file attached is in zip form as it is of large size. If you required the file corresponding to 6x6 or 18x18 matrix cases(for which the given code works nicely), I will attach those separately.</p><p>I am egerly waiting for your quick response.</p><p>thank you.</p>Kamal Berahttp://de.mathworks.com/matlabcentral/profile/authors/5530127-kamal-beratag:de.mathworks.com,2005:Question/2103982015-04-19T19:16:30Z2015-04-19T21:16:51Zsub2ind - covert x y z vectors into 3D matrix<p>I want to do the inverse of this code....</p><pre> w=size(data,1);
l=size(data,2);
h=size(data,3);
[x,y,z]=ind2sub([w,l,h],find(data(:)));</pre><p>Something like this:</p><pre class="language-matlab">data=sub2ind(size(data),x,y,z);
</pre><p>So I want to extract the indices and then return the data back into its original form</p><p>May thanks,</p>Williamhttp://de.mathworks.com/matlabcentral/profile/authors/5011478-williamtag:de.mathworks.com,2005:Question/2104122015-04-19T20:52:12Z2015-04-19T20:52:12Zhow can i make m file take 2 matrices from the user <p>M file . take 2 matrices from the user regardless the size then multiply them whatever they are valid or not</p>abdelrhman elkadyhttp://de.mathworks.com/matlabcentral/profile/authors/6290632-abdelrhman-elkadytag:de.mathworks.com,2005:Question/2104042015-04-19T20:11:50Z2015-04-19T20:51:01Z 2D histogram for field distribution<p>I have a problem with the 2d histogram attach file.
I have the coordinates (x,y) of a lot of soccer players and i want to know their field distribution and how many times each palyer is in each "N" bens of the field.
Using the 2d histogram code, i have a quetions?</p><p>- table size: 120m x 90m (same of soccer field)
- bens size: 1m2
- N bens= 10800</p>Sérgio Queridohttp://de.mathworks.com/matlabcentral/profile/authors/6420976-sergio-queridotag:de.mathworks.com,2005:Question/2104112015-04-19T20:50:05Z2015-04-19T21:58:35ZMatlab slow in for loop with large number of iterations but not with a small one<p>Hi,</p><p>I am running a function to extract some information from 100,000+ patient xray dicom files. the files are stored within a veracrypt encryption container for security purposes.</p><p>when i run the function on a small sample of files it performs really quickly, however when i run the function on the entire dataset it is very slow in comparison, going from several files per second to 1 file per second (approximately).</p><p>i was wandering why this is happening? i have tried storing the data on an ssd and on a normal hard drive and get the same sort of slow down when using a larger dataset compared to a small one.</p><p>i have added the code below for reference but haven't commented it fully yet.. this is for my thesis so i will do it once i get the extraction finished..</p><p><b>thanks for any help.</b></p><pre class="language-matlab">function [ DB, corrupted_files ] = extract_from_dcm( folder_name )
%EXTRACT_FROM_DCM Summary of this function goes here
% Detailed explanation goes here
</pre><pre class="language-matlab">if nargin == 0
folder_name = 'G:\medium2';
end
</pre><pre class="language-matlab">Database_Check = strcat(folder_name, '\DataBase.mat');
</pre><pre class="language-matlab">if exist(Database_Check, 'file')
</pre><pre> load(Database_Check);
entry_start = length(DB) + 1;</pre><pre class="language-matlab">else
</pre><pre> entry_start = 1;
[ found_dicoms ] = recursive_search( folder_name );</pre><pre class="language-matlab">end
</pre><pre class="language-matlab">mat_file_location = strcat(folder_name, '\DataBase.mat');
excel_DB_file = strcat(folder_name, '\DataBase.xlsx');
excel_Corrupted_file = strcat(folder_name, '\Corrupted_Files.xlsx');
</pre><pre class="language-matlab">% the recursive search creates a struct with the path for each
% dcm file found. the list is then recursivly used to locate
% the image and extract the relevant information from it.
</pre><pre class="language-matlab">fprintf('---------------------------------------------\n');
fprintf('Start Patient Data Extraction\n');
tic
h = waitbar(0,'','Name','Patient Data Extraction');
entry_end = length(found_dicoms);
</pre><pre class="language-matlab">if entry_end == 0
</pre><pre> % error message goes here.</pre><pre class="language-matlab">else
</pre><pre> for kk = entry_start : entry_end
progress = kk/entry_end;
progress_percent = round(progress * 100);
waitbar(progress,h, sprintf('%d%% %d/%d of images processed', progress_percent, kk, entry_end));</pre><pre> img_full_path = found_dicoms(kk).name;</pre><pre> % search_path = folder_name;
% img_full_path = strrep(img_full_path, search_path, '');</pre><pre> try %# Attempt to perform some computation
dicom_info = dicominfo(img_full_path); %# The operation you are trying to perform goes here
catch exception %# Catch the exception
continue %# Pass control to the next loop iteration
end</pre><pre> try %# Attempt to perform some computation
dicom_read = dicomread(dicom_info); %# The operation you are trying to perform goes here
catch exception %# Catch the exception
continue %# Pass control to the next loop iteration
end</pre><pre> old = dicominfo(img_full_path);</pre><pre> DB(kk).StudyDate = old.StudyDate;
DB(kk).StudyTime = old.StudyTime;</pre><pre> if isfield(old.PatientName, 'FamilyName')
DB(kk).Forename = old.PatientName.FamilyName;
else
DB(kk).Forename = 'NA';
end</pre><pre> if isfield(old.PatientName, 'GivenName')
DB(kk).LastName = old.PatientName.GivenName;
else
DB(kk).LastName = 'NA';
end</pre><pre> if isfield(old, 'PatientSex')
DB(kk).PatientSex = old.PatientSex;
else
DB(kk).PatientSex = 'NA';
end</pre><pre> if isempty(old.PatientBirthDate)
DB(kk).PatientBirthDate = '00000000';
else
DB(kk).PatientBirthDate = old.PatientBirthDate;
end</pre><pre> if strcmp(old.Manufacturer, 'Philips Medical Systems')
DB(kk).Van = '1';
else
DB(kk).Van = '0';% section to represent organising by different vans
end</pre><pre> DB(kk).img_Path = img_full_path;</pre><pre> save(mat_file_location,'DB','found_dicoms');</pre><pre> end</pre><pre class="language-matlab">end
</pre><pre class="language-matlab">[ corrupted_files, DB ] = corruption_check( DB, found_dicoms, folder_name );
</pre><pre class="language-matlab">toc
fprintf('End Patient Data Extraction\n');
fprintf('---------------------------------------------\n');
</pre><pre class="language-matlab">fprintf('---------------------------------------------\n');
fprintf('Start Saving Extracted Data \n');
tic
</pre><pre class="language-matlab">save(mat_file_location,'DB','corrupted_files','found_dicoms');
</pre><pre class="language-matlab">if isempty(DB)
msg = sprintf('No Dicom Files Found');
msgbox(strcat(msg));
else
DB_table = struct2table(DB);
writetable(DB_table, excel_DB_file);
end
</pre><pre class="language-matlab">if corrupted_files.num_corrupted > 0
Corrupted_Files = struct2table(corrupted_files);
writetable(Corrupted_Files, excel_Corrupted_file);
else
msg = sprintf('No Corrupted Files Found');
msgbox(strcat(msg));
end
</pre><pre class="language-matlab">close(h);
</pre><pre class="language-matlab">toc
fprintf('End Saving Extracted Data \n');
fprintf('---------------------------------------------\n');
</pre><pre class="language-matlab">end
</pre>bilalYhttp://de.mathworks.com/matlabcentral/profile/authors/5712167-bilalytag:de.mathworks.com,2005:Question/2104102015-04-19T20:49:44Z2015-04-19T20:49:44ZIs it possible to modify gstreamer used by matlab to specific functionality?<p>I am working on a problem that requires me to access motion vectors from an H.264 video stream for the purpose of motion detection. I currently have this working using the JM H.264 reference software which is written in C. Problem is for prototyping this is pretty painful and time consuming. Any time I need certain feature, I have to write the algorithm and code from scratch. For example, to perform blob analysis to detect objects, I have to write the code from scratch vs. Matlab where it is a single line of code.</p><p>What I would like to do is modify gstreamer to provide an interface that delivers motion vectors, then recompile gstreamer and have Matlab use that new interface. The data can then be manipulated by Matlab and overlaid over video using standard Matlab functions.</p><p>Anyone aware if this is doable, or has been done? Any tips would be greatly appreciated.</p>Mo Alhroubhttp://de.mathworks.com/matlabcentral/profile/authors/2056844-mo-alhroubtag:de.mathworks.com,2005:Question/2103472015-04-19T13:26:54Z2015-04-19T20:59:52ZHelp with for loop <p>Hi, I have a for loop where d is a 100x1 array and d0 is the average value of the elements in d. I would like to know how I can change it so after each iteration I have a 100x1 result in final_table and after all iterations are completed the variable final_table is a 100x100 array. The way I have implemented the if loop is incorrect since I finish with a 50x100 array. What I am trying to implement is to go through the different values of d, if less than the average d0 then calculate final (variables final_N1 and final_No) to hopefully finish with a 100x1 result and repeat 100 times to finish with 100x100 array in final_table. Thanks.</p><pre class="language-matlab">for cnt=1:100
if d(cnt)<=d0
No=sum(d<=d0);
d_pos_No=find(d<=d0);
d_pos_No=d(d_pos_No);
final_No=d_pos_No/No;
final_N1=zeros(size(final_No));
else
N1=sum(d>d0);
d_pos_N1=find(d>d0);
d_pos_N1=d(d_pos_N1);
final_N1=d_pos_N1/No;
final_No=zeros(size(final_N1));
end
final_table(1:numel(final_No+final_N1),cnt)=final_No+final_N1;
end
</pre>ajk1http://de.mathworks.com/matlabcentral/profile/authors/3936610-ajk1tag:de.mathworks.com,2005:Question/2104082015-04-19T20:35:32Z2015-04-19T20:47:17ZMethod for reducing error with multiple constants and input variables<p>So I'm new to this forum, if I've done anything wrong in the way I've asked this question then apologies.</p><p>Basically I have a pretty complicated system which I am trying to model in Matlab. I have a large amount of measured data, and I am taking a sample of 30 representative operating points, each with about 7000 measurements at different conditions. The value which is trying to be modelled can be called x. I have a structure for a model which uses measured input variables at each point and a system of equations (with overall 6 constants) outputs a value for modelled x. I am trying to optimise the model by changing the value of these 6 constant values such that the deviation between the model and the measured value of x and derivative of x at each point is minimised. I had thought to quantify this by counting the number of points where the percentage deviation is +/- 20%, and try and minimise the number of points where this occurs.</p><p>The problem I have is that obtaining measured data for each of these operating points takes roughly 2 minutes, which means that all thirty points takes around an hour to run. Therefore optimising the calibration can not realistically be done by randomly varying the values of these 6 constants. I would like to know if there is a mathematical process by which these constants can be optimised, whilst minimising the number of iterations taken to do so?</p><p>If anything isn't clear in what I've explained, just let me know and I'll try and clarify it.</p><p>Thanks in advance,</p><p>Alex</p>Alex Sherwoodhttp://de.mathworks.com/matlabcentral/profile/authors/6432013-alex-sherwoodtag:de.mathworks.com,2005:Question/2104092015-04-19T20:46:16Z2015-04-19T20:50:53ZHow can I produce the ROC curve with EER for a probabilistic neural network<p>I need to produce the ROC curve for a probabilistic neural network with these targets and outputs:</p><p>t=[1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1];</p><p>out=[1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 1 0 1 1 0 0 0 1 0 0 0 0;
0 0 0 0 0 1 0 0 1 1 1 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1];</p><p>I used the plotroc instruction in Matlab, but unfortunately the figure was not a curve. So could anyone help me, please?. Also, I want to ask how can I calculate the EER, and get the relationship figure between FAR and FRR?</p>Raid Omarhttp://de.mathworks.com/matlabcentral/profile/authors/3181922-raid-omartag:de.mathworks.com,2005:Question/2104022015-04-19T19:54:09Z2015-04-19T20:42:48ZHow can I create a structure from a cell array of strings and give it the initial value of zero?<p>given:</p><p>a={</p><pre> 'S.f1' 'double' [1, 600] ;</pre><pre> 'S.f2' 'uint8' [5,5];</pre><pre> 'S.f3.ff1' 'int16' [5,2,10]; </pre><pre> 'S.f3.ff2' 'double' [1,60] }</pre><p>I would like to have in my workspace contain a structure "S"
having fields f1, f2, and f3, and I want f3 to have fields ff1 and ff2.</p><p>I do not want to explicitly type out :</p><pre> S.f1 = zeros(1,600,'double');</pre><pre> S.f2 = zeros(5,5,'uint8');</pre><pre> S.f3.ff1 = zeros(5,2,10,'int16');</pre><pre> S.f3.ff2 = zeros(1,6,'double');</pre><p>I am stumped by the fact that MATLAB does not recognize 'S' as a structure when I try to parse the assignment statements from 'a'.</p><p>x = cellfun (@zeros, a{:,3},a{:,2},'UniformOutput',false);</p><p>S=cell2struct(x,a{:,1},1);</p><p>does not work, nor does</p><p>evalin ('base',strcat(a{1,1}, '= ',x{1}));</p><p>please help.</p>Martahttp://de.mathworks.com/matlabcentral/profile/authors/3035583-martatag:de.mathworks.com,2005:Question/2040042015-04-16T23:50:16Z2015-04-19T20:31:16ZPlayers distribution in soccer field<p>Hello,</p><p>I have the coordinates (x,y) of a lot of soccer players and i want to know their field distribution.
I want to part the field (120m x 90m) in 1m2 bens. With this, i want to now how many times, players are in each bens.</p><p>Can you help me please with the best code to run this in matlab?</p><p>SQ</p>Sérgio Queridohttp://de.mathworks.com/matlabcentral/profile/authors/6420976-sergio-queridotag:de.mathworks.com,2005:Question/2104072015-04-19T20:27:46Z2015-04-19T20:27:46ZHow can I Optimize a multivariable function with Least Square method?<p>Hi</p><p>I have a function to measure chloride content in concrete:</p><p>cxt =cs-(cs-ci)*erf((x*0.001)/(sqrt(4*da*t))</p><p>where cxt is chloride content.ci is a constant, x is a vector for depth containing 11 values,and t is a constant.</p><p>Through testing I have collected some data for cxt. I want to know what values of cs and da minimize the sum of least sqaures so this function can fit my collected lab data.</p><p>More info:</p><p>this is the code I have written to get cxt for some arbitrary values for cs and da but I dont know how to find the optimal values:</p><img src = "/matlabcentral/answers/uploaded_files/29355/screen.JPG">Mahmoud http://de.mathworks.com/matlabcentral/profile/authors/5983167-mahmoudtag:de.mathworks.com,2005:Question/1966552015-04-08T06:26:20Z2015-04-19T20:26:48Zlinear least squares/mldivide for large matrices in parallel?<p>I have a really large system to solve using linear least squares. The A matrix can have 2-3 million rows and 2000-3000 columns. The B matrix has same row size but with a single column.</p><p>I have access to a supercomputer, and I want to run the x = A\B (or) mldivide(A,B) command in parallel, since I can easily run out of RAM even on workstations with lots of memory.</p><p>Any ideas? I am able to run EIG and SVD without any issues in parallel, since I assume it is
automatically parallelized by MATLAB. What about linear least squares? Suggestions outside of MATLAB are also welcome. Thanks.</p>Arvindhttp://de.mathworks.com/matlabcentral/profile/authors/3011234-arvindtag:de.mathworks.com,2005:Question/2104062015-04-19T20:14:00Z2015-04-19T20:14:00Zfsolve matlab: No solution found<p>function F = Emissionangle(x)
R_t = 1.4;
R_mic = 1.6;
U = 20
M = U/340
a_o = 340;
a_t = 340;
theta_mic=135
F = [ atand(sin(x(2))/(cosd(x(2))-M))-x(1);
R_mic*cosd(theta_mic) - (R_t/tand(x(1)))-(( R_mic*sind(theta_mic)-R_t)/tand(x(3)));
M - (1/cosd(x(2))) + (a_o/(a_t*cosd(x(3))))]
xo =[ 135,135,135].
fsolve(@Emissionangle,xo)</p><p>I am not sure about the initial guess solution. I dont get a converged solution. Any help</p>viswanath channahttp://de.mathworks.com/matlabcentral/profile/authors/4088688-viswanath-channatag:de.mathworks.com,2005:Question/2104012015-04-19T19:52:01Z2015-04-19T20:06:18Zundefined function variable 'x'<pre class="language-matlab">Hi all,
My code doesn't work, I'm pretty sure the logic is correct. it always gives me ' undefined function variable x'. I don't know how to make it work. Seems like the handling function @x....
I show the code below. Thanks all!
</pre><pre> syms x</pre><pre> for i = 2 : 1
b = 0;
a = i + 1;
for j = 1 : i
b = SP(j,i) * p * PR(j,i) * ((exp(-(R(j,i) + x * dt + d) * dt) + exp(-(R(j,i) + x * dt - d) * dt))) + b;
end
H(i) = fsolve(@(x)P(a) - FV * b, 0.1);
for m = 1 : i
R(m,a) = R(m,i) + H(i) * dt + d;
PR(m,a) = exp(-R(m,a) * dt);
end
for aa = 2 : 10
a = aa + 1;
SP(1,a) = p * SP(1,aa) * PR(1,aa);
L = SP(1,a);
for bb = 2 : aa
SP(bb,a) =p * SP(bb,bb) * PR(bb,bb) + L;
L = SP(bb,a) + L;
end
SP(aa+1,a) = p * PR(aa,aa) * SP(aa,aa);
end
end</pre>JENNY CHENGhttp://de.mathworks.com/matlabcentral/profile/authors/5215628-jenny-chengtag:de.mathworks.com,2005:Question/2103782015-04-19T17:59:10Z2015-04-19T19:59:18ZHow to change the text on a pushbutton in the code, not using property inspector<p>We have one GUI where a user selects a region from a drop down menu, which is assigned to a number (1 through 6), we then pass that number to another GUI. The second GUI has two ouch buttons labeled city 1 city 2, but we need to change the string to actual city names based on what region the user selected. We set up an if statement for each region and within those if statements we can't figure out how to change the string that the user will see, or how to go about it.</p>Taylor Esteehttp://de.mathworks.com/matlabcentral/profile/authors/6431609-taylor-esteetag:de.mathworks.com,2005:Question/734822013-04-25T02:02:29Z2015-04-19T19:46:18Zhow can i get Interval Type-2 Fuzzy Logic System Toolbox<p>A lot of people begin to use interval Type -2 fuzzy logic system to do some researchs,The book <a href = "Type-2">Fuzzy Logic: Theory and Applications</a> has already develop the IT2FLS Toolbox whic is just like the fuzzy logic box ,But i cannot find it on the internnet .i think the toolbox is helpful for those who dedicated in this field .so If you already have this software ,could you send it to me ,I really appreciate it .</p>Wu Xianghttp://de.mathworks.com/matlabcentral/profile/authors/3813593-wu-xiangtag:de.mathworks.com,2005:Question/2103952015-04-19T18:41:50Z2015-04-19T19:38:38Zchange the ploted node location every 1 second<p>suppose i plot some nodes on the graph and i wish to change the node location every second .</p><pre> node=20;
area=100;
X=rand(1,node)*area;
Y=rand(1,node)*area;
for i=1:node
plot(X(i),Y(i));
text(X(i),Y(i),num2str(i));
end</pre>singhhttp://de.mathworks.com/matlabcentral/profile/authors/6334127-singhtag:de.mathworks.com,2005:Question/2103522015-04-19T14:32:25Z2015-04-19T19:34:46ZOptimize/speed up a big and slow matrix operation with addition and bsxfun?<p>Hi. I have a fairly long line of code in my script that takes about 7 seconds to run, it was originally three separate calculations but are now done in one line that looks like this:</p><pre class="language-matlab">X = bsxfun(@times,reshape(bsxfun(@times,A,B),[1440,1,2251]),(1-C)./2)...
+bsxfun(@times,reshape(E,1440,1,2251),D)...
+bsxfun(@times,reshape(F,1440,1,[]),((1+C)/2));
</pre><p>Since I need to run it several tens of thousands times it is causing a fair amount of anxiety in my life at the moment. I don’t know how I would go about speeding it up further or if it is even possible. So I would really appreciate it if any of you optimization gurus here could give me some advice on how and if I can go about making this faster.</p><p>The input variables are of size:</p><pre class="language-matlab">A = 2251x1
B = 1440x2251
C = 1x181
D = 1440x181
E = 1440x2251
F = 1440x2251
</pre><p>Thanks!</p>PetterShttp://de.mathworks.com/matlabcentral/profile/authors/5894292-petterstag:de.mathworks.com,2005:Question/2103672015-04-19T15:47:10Z2015-04-19T19:27:28ZRed Ball Tracking Problem <p>Hi. I have a question. A maked project wich should track a red ball. But appear the problem which bedevil me. There i put my code , if someone can help me, please.</p><pre class="language-matlab">if true
imaqhwinfo
dev_info = imaqhwinfo('winvideo',1)
%info=imaqhwinfo('winvideo')
</pre><pre> celldisp(dev_info.SupportedFormats)
vid=videoinput('winvideo',1,'YUY2_640x480');
%% Set the properties of the video object
set(vid, 'FramesPerTrigger', Inf);
set(vid, 'ReturnedColorspace', 'rgb')
vid.FrameGrabInterval = 5;
%Achizitie video
start(vid)
%Initializare arduino
ser=serial('COM3','Baudrate',9600);
fopen(ser)</pre><p>while(vid.FramesAcquired<150)
data = getsnapshot(vid);
%din gray extragem componenta rosie
r = data(:,:,1);g = data(:,:,2); b = data(:,:,3);
bw1 = ((r >=248) & (g <=2) & (b <=2));
%bw1 = (r - g/2 - b/2);
% % stergem pixelii mai mici deci 30
bw1 = bwareaopen(bw1,30);
bw = imfill(bw1,'holes');
[B,L] = bwboundaries(bw,'noholes');
%figure(1); subplot(224); imshow(bw1);
%nr de componente conectate din imagine
%bw = bwlabel(bw1, 8);
% bw1 = imfill(bw1,'holes');
% [B,L] = bwboundaries(bw,'noholes');
%Blob analiza
stats = regionprops(L,'Area','Centroid');
circle_threshold = 0.80;
figure(1);
imshow(data);
hold on
for g = 1:length(B)</p><pre> % obtain (X,Y) boundary coordinates corresponding to label 'g'
boundary = B{g};</pre><pre> % compute a simple estimate of the object's perimeter
delta_sq = diff(boundary).^2;
perimeter = sum(sqrt(sum(delta_sq,2)));</pre><pre> % obtain the area calculation corresponding to label 'g'
area = stats(g).Area;</pre><pre> % compute the roundness metric
metric = 4*pi*area/perimeter^2;
if metric > circle_threshold
bc = stats(g).Centroid;
plot(bc(1),bc(2),'ko');
a=text(bc(1)+16,bc(2),strcat('X: ',num2str(round(bc(1))),' Y: ', num2str(round(bc(2)))));
set(a, 'FontName', 'Arial', 'FontWeight','bold','FontSize',12,'Color','yellow');
%Poz=uint8(bc(1));</pre><pre> X = round(bc(1));
% valoarea_prag = 60;
% Xc = 320;%320;
[pancmd] = pantilt(X);
fwrite(ser,pancmd,'char');
% if (Xc-X) > valoarea_prag
% fprintf(ser,'r');
% %%Find out if the X component of the face is to the right of the middle of the screen.
% elseif (X-Xc) > valoarea_prag
% fprintf(ser,'l');
% end
else
[r,c] = find(L(:,:)==g);
% [r,c] = find(bwlabel(bw)==g);
bw(r,c)=0;
end
end</pre><pre> % pause
hold off
end
%b.servoWrite(9,0);
%pos = b.servoread(1);</pre><p>%oprire achizite video
closepreview(vid)
stop(vid);
%delete(vid)</p><p>fclose(ser)
%sterge toate variabilele
clear all
sprintf('%s','gata')
end</p>Stas Radionhttp://de.mathworks.com/matlabcentral/profile/authors/6431271-stas-radiontag:de.mathworks.com,2005:Question/2103912015-04-19T18:19:04Z2015-04-19T19:23:33ZExponential curve fitting- "line" of best fit - basis functions - polyfit<p>I need to fit data to an exponential curve. I know the actual formula of the curve is:
v(T) = exp(c0 + c1*T) where T is Ti and c0 and c1 are unknowns that I am solving for to fit the curve of data points. So I am looking for c0 and c1, and then trying to plot them.</p><p>I'm trying to do this with basis functions, but if you can solve it with polyfit that would be ok.
MY basis functions are:
�A=[exp(Ti.^0),Ti]; %probably not correct
and then solve with formula "c=A\y" where A is as above and y is my y-values.
so my code for that is
c=A\log(vi); Then I try to put those c0 and c1, or c(1), c(2), into an anonymous function and trying to plot that, but it doesn't work correctly.</p><p>Could you please find c0 and c1 correctly and find a way to plot it correctly so it is a "line of best fit". (Doesn't have to be perfect, but I need it to go with the curve)</p><p>MY PROGRAM:</p><p>Ti=[10 20 30 40 50 60 70 80 90]'; % my x values - celsius temp</p><p>vi=[1.31 1.00 0.80 0.65 0.55 0.47 0.40 0.36 0.32]'; % my y values</p><p>A=[exp(Ti.^0),Ti]; % trying to use a basis function</p><p>c=A\log(vi);</p><p>%c(1)=exp(c(1));</p><p>%c(2)=c(2);</p><p>T=linspace(10,90,101); % GENERATING x values</p><p>Tk=T+273.15; % converting Ti, convert Celsius to kelvin</p><p>f=@(c,Tk) c(1)+c(2).*Tk; % my function, notice no exp() on outside, I mean it is of
% form v(T) = exp(c0 + c1*T)</p><p>plot(T,(f(c,Tk)),'b-',Ti,vi,'rd')</p>Ar Gofhttp://de.mathworks.com/matlabcentral/profile/authors/6428239-ar-goftag:de.mathworks.com,2005:Question/2103772015-04-19T17:54:29Z2015-04-19T19:22:47Zcan any one help me in detecting an error in matlab code please ? <pre class="language-matlab">pih=[];
for im=1:0.1:20
n=15;
</pre><pre> i=13;
k=8;
m=2;
h=3;
f=factorial(n)/(factorial(i)*factorial(n-i));</pre><pre> g=factorial((2^(k-(m*h)))*factorial(i)*factorial((2^(k-(m*h)))-i));
p=factorial((2^k))/factorial(i)*factorial((2^k)-i);
j=g/p;</pre><pre> o=factorial((2^k)-(2^(k-(m*h))))/factorial(n-i)*factorial((2^k) ...
-(2^(k-(m*h)))-(n-i));</pre><pre> u=factorial((2^k)-i)/factorial(n-i)*factorial((2^k)-i-(n-i));
z=o/u;
pih=f*j*z;
end</pre><pre> #
this is the code and this is the error message :
#??? Error using ==> factorial at 17
N must be a matrix of non-negative integers.</pre><p>Error in ==> marwa at 12
g=factorial((2^(k-(m*h)))*factorial(i)*factorial((2^(k-(m*h)))-i));</p><p>??? Error using ==> factorial at 17
N must be a matrix of non-negative integers.</p><p>Error in ==> marwa at 12
g=factorial((2^(k-(m*h)))*factorial(i)*factorial((2^(k-(m*h)))-i));
#</p>safi marwahttp://de.mathworks.com/matlabcentral/profile/authors/6431600-safi-marwatag:de.mathworks.com,2005:Question/2103972015-04-19T19:02:13Z2015-04-19T19:10:32ZCommunications Toolbox System Objects<p>I am trying to use the Communications Toolbox in Matlab. In this toolbox there are a number of built in Systems Objects for example</p><p>1) comm.LTEMIMOChannel</p><p>2) comm.SphereDecoder.</p><p>I want to examine the .m file and see how these system objects are implemented. So I wrote down the command</p><p>open comm.LTEMIMOChannel</p><p>However, that doesnt help. Does anyone know why it doesn't work or maybe one cant access such code?</p><p>Thanks</p>Georgehttp://de.mathworks.com/matlabcentral/profile/authors/5723273-georgetag:de.mathworks.com,2005:Question/2102192015-04-18T11:52:35Z2015-04-19T18:54:32ZI'm trying to find a second tumor within my data but I can't <p>my data contains three tumors where I was able to define the position of the first tumor by the max fuction however I can find the second max but the problem is that the force that is directly lower that the max force is also a part of that tumor but want I want is to skip all of these unnessacery forces that are part of that tumor and look for other tumors. I'll attach the picture so you can understand more ....</p><p>I appreciate any help thanks ...</p>Ahmed Alnahdihttp://de.mathworks.com/matlabcentral/profile/authors/6427362-ahmed-alnahditag:de.mathworks.com,2005:Question/2103252015-04-19T10:05:06Z2015-04-19T18:47:18Zto send a message to one another node<pre> node=20;
area=100;
X=rand(1,node)*area;
Y=rand(1,node)*area;
for i=1:node
plot(X(i),Y(i));
text(X(i),Y(i),num2str(i));
end</pre><pre> now i wish to send particular node detail(node no,node coordinates) send to another node.</pre><pre> suppose i want send node (no-5) details to node (no-14).</pre><p>and calculate how much time consume to reach this detail to destination node(no-14)</p>singhhttp://de.mathworks.com/matlabcentral/profile/authors/6334127-singhtag:de.mathworks.com,2005:Question/2102842015-04-18T22:49:40Z2015-04-19T18:42:20ZHow can I combine these two codes<p>I need help creating a plot of streamlines over an ellipse for a school assignment</p><p>The two codes that I am using are</p><pre class="language-matlab">% Plot streamlines and pressure coefficent of an unviscious,uncomprimibile,irrotational
% flow around a cylinder section (radius = 1) that spins around the z axis (coming out
% of the xy plane).
% This result is achieved by superimposition of elementary solution of the potential
% function PHI, where [Ux , Uy] = GRAD(PHI) which comprehend Uniform Stream,Doublet,Vortex.
% This case rappresents a good example of Magnus Effect,that is the reason why spinning
% balls have an effected trajectory.And rappresent the basis of Kutta-Joukowski theory.
%
%
% INPUT
% V_i = Asymptotic Speed
% G = Angular Speed (positive anti-clockwise)
%
% -----EXAMPLE------
% V_i = 20
% G = 50
%
% Created by: Dario Isola
% DATA : 24/03/2004
% Politecnico di Milano - Aerospatial Engeeniering Departement
%----------
%Modification log
%Author Date Description
%----------------------------------------------------------------------------------
%Yogesh PARTE,IMT Toulouse 15 Jan 2010 Added Cp distribution plot
% over a cylinder see
% figure(4), removed for loop, added comments
%----------------------------------------------------------------------------------
</pre><pre class="language-matlab">close all;
</pre><pre class="language-matlab">clear all;
</pre><pre class="language-matlab">%% Input section
V_i = input(' Asymptotic speed V_0 [m/s] = ');
G = input(' Circulation Value G [rad/s] [Anti-clockwise] = ');
</pre><pre class="language-matlab">%% Actual computation
%Radius of the circle
a = 3.5 ;
c =-a*2;
b =a*2;
</pre><pre class="language-matlab">% Number of intervals
n =a*50;
</pre><pre class="language-matlab">[x,y]=meshgrid([c:(b-c)/n:b],[c:(b-c)/n:b]');
</pre><pre class="language-matlab">warning off;
</pre><pre class="language-matlab">%%Preliminary DATA & purification
</pre><pre class="language-matlab">% Set values of X and Y inside the cylinder to zero
[I J]=find( (x.^2+y.^2) < a);
</pre><pre class="language-matlab">if ~isempty(I)
x(I,J) = 0;
y(I,J) = 0;
end
</pre><pre class="language-matlab">%Definition of polar variables
rho=sqrt(x.^2+y.^2);
</pre><pre class="language-matlab">theta=atan2(y,x);
</pre><pre class="language-matlab">% Creation of the streamline function
z=V_i.*sin(theta).*rho.*(1-(a^2./(rho.^2)))-G*log(rho)/(2*pi);
</pre><pre class="language-matlab">%% Generate unite cicle for plotting
n=100;
r=ones(1,n+1)*a;
t=[0:2*pi/n:2*pi];
</pre><pre class="language-matlab">Xcircle = r.*cos(t);
Ycircle = r.*sin(t);
%% Plot the data
</pre><pre class="language-matlab">% Streamline Plot
figure(1);
contour(x,y,z,25);
colorbar;
hold on;
fill(Xcircle,Ycircle,'k');
title('Stream Lines');
xlabel('x \rightarrow');
ylabel('y \rightarrow');
axis square;
</pre><p>This is code that I found online for streamlines over a circle.</p><p>The other code is</p><pre class="language-matlab">clc,clear
a=5.5; %horizontal radius
b=3.50; %vertical radius
x0=0; % x0,y0 ellipse centre coordinates
y0=0;
t=-pi:0.01:pi;
x=x0+a*cos(t);
w=y0+b*sin(t);
plot(x,w)
grid on
</pre><p>This is to plot an ellipse.</p><p>My problem is that I need the second code to be somehow integrated into the first code which is the stream line code.</p><p>Any help would be great because my professor would like to see some sort of MATLAB use out of our project.</p><p>Thank you.</p>Haim Matharuhttp://de.mathworks.com/matlabcentral/profile/authors/3975863-haim-matharutag:de.mathworks.com,2005:Question/2102852015-04-18T23:02:38Z2015-04-19T18:41:28ZHow can I store an array from a called function to another array?<p>I have a function Sysmodel(), which calculates the value of an array B based on random variables. What I want is to store different values of B to later take an average, something like monte carlo simulations. When I try to do this, I only get an array of zeros with the last row filled with B from the last iteration. My code is this:</p><pre class="language-matlab">for i = 1:1000
Sysmodel()
A(i,:)=B;
end
</pre><p>Could you point out where I am going wrong? Or give me a better way to carry out these simulations?</p>Kirtiman http://de.mathworks.com/matlabcentral/profile/authors/4656928-kirtimantag:de.mathworks.com,2005:Question/2103932015-04-19T18:31:37Z2015-04-19T18:31:37ZHow can I solve the problem at the download of the file R2015a?<p>I have got Windows 8 64 Bit. I downloaded Matlab the version R2015a. But after unzipping the file there was an error which said "Error finding installer class. An exception occurred while looking for class."</p><p>How can I solve this problem.</p><p>I need the solution as far as possible.</p><p>Bye</p>Ömer Oralhttp://de.mathworks.com/matlabcentral/profile/authors/6430676-omer-oraltag:de.mathworks.com,2005:Question/2103922015-04-19T18:24:29Z2015-04-19T18:24:29Zhow to apply k-mean clustering method to exact the spot intensity in DNA microarray image<p>hi....
i m 4th fourth student currently doing a research project on image processing using matlab, as i seen in matlab the DNA MicroArray Image Processing Case Study.'http://www.mathworks.com/matlabcentral/fileexchange/2573-dna-microarray-image-processing-case-study'
the step it use is to seperate the image to 3 layer red,green and yellow. from there can get the color intensity and then make calculation to get final intensity.
what about if using k-mean clustering, i read some paper online it show that in k-mean cluster method, we cluster the pixel, how to cluster the image pixel using matlab. and how many group we need to cluster. thank</p>SK YONGhttp://de.mathworks.com/matlabcentral/profile/authors/6417768-sk-yongtag:de.mathworks.com,2005:Question/2103792015-04-19T18:11:31Z2015-04-19T18:17:09ZHow Do I Apply Multiple Conditions On An Array<p>I have found the center of masses of a stack of 148 images (64x32), what I want to do is divide the 64x32 image into quadrants, and to group all the center of masses (148x2) together in their respective quadrant (1,2,3 and 4).
This is what I am working with:</p><p>numpool = size(LA_maxDF_M, 3);
area = zeros(numpool, 1);
c = zeros(numpool, 2);</p><p>%% Converting to binary; Calculating center of mass and area
for pool = 1:numpool;
binimage = im2bw(LA_maxDF_M(:, :, pool),0.5);
area(pool) = bwarea(binimage); % calculate surface area of binary image.
binimage = double(binimage);
c(pool,:) = centerOfMass(binimage); % calculate centre of mass of binary image
plot(c(:,1),c(:,2),'.');
axis([min(c(:,1)) max(c(:,1)) min(c(:,2)) max(c(:,2))])
x_c = c(:,1);
y_c = c(:,2);</p><p>for example, for quadrant 3 ind and ind2 are the two conditions I want to satisfy:
ind = find(x_c < max(x_c)/2);
ind2 = find(x_c > min(x_c));
they work separately but I want both conditions to apply together, i.e. I want all the center of masses which are within the region: min(x_c) < x_c < max(x_c)/2 and
min(y_c) < c(:,2) < max(y_c)/2 to group together.
Help on this would be much appreciated.</p>Ahmed Ismailhttp://de.mathworks.com/matlabcentral/profile/authors/5780105-ahmed-ismailtag:de.mathworks.com,2005:Question/2103802015-04-19T18:13:41Z2015-04-19T18:13:41ZHow I can create matrices from a cell with a loop if the dimensions of matrices are not consistent?<p>Dear All,</p><p>I have an out(301,1) cell which contains data in function of longitude, latitude and time in each months from 1961 to 1990. The longitude and latitude dimensions are same but the time is different because its lenght depends on the number of days of months. So the out cell looks like:
out = {(464x201x31), (464x201x28), (464x201x31), (464x201x30)...}.
Could someone write me how I could create matrices from this cell with a loop?</p>Szabó-Takács Beátahttp://de.mathworks.com/matlabcentral/profile/authors/6427862-szabo-takacs-beatatag:de.mathworks.com,2005:Question/2103102015-04-19T08:49:35Z2015-04-19T18:05:05Zhow to perform jump condtion or alternative solution for calling <p>Suppose I take input at command window through input command</p><p>If it is in array then it show that value which was i enter</p><p>or if it is not in array then it will jump to take input again..</p><pre> N=input('enter the no: ');
N1=X(N,:) it will show the coordinate value of N in the array X</pre>singhhttp://de.mathworks.com/matlabcentral/profile/authors/6334127-singhtag:de.mathworks.com,2005:Question/2103762015-04-19T17:52:51Z2015-04-19T17:52:51ZBER simulation in cdma system<p>hi there, i'm doing one ber simulation in a cdma system, here is my code:
/////////////////////////////////////////////////////////////////////////////////
clear all;
close all;</p><p>N=30; %number of spreading sequence
K=10; %number of users
M=10^4; %total number of symbols
num=N*M;
snr=[-3:15];
snr_linear=10.^(snr/10);</p><p>S=sign(randn(N,K))/sqrt(N);
R=S'*S;
b=sign(randn(K,M));
n=1/sqrt(2)*(randn(N,M)+i*randn(N,M));
encode=S*b;</p><p>for i=1:length(snr)
n1=1./sqrt(2*snr_linear(i))*n
y=encode+n1;
%%Match filter
x_mf=sign(real(S'*y));
numErr_mf(i)=sum(sum(b~=x_mf));
end;
////////////////////////////////////////////////////////////////////////////////////////
But there is one problem. when i run this, there will be the situation that the spreading sequence could be worse, my supervisor suggest me move the equation 'S' 'b' 'n' inside the loop, so it could be generated new bits very time, then there no more questions. But i have try many time , still not work. So i hope someone can help me here, Thanks.</p>LINXIAN ZHUhttp://de.mathworks.com/matlabcentral/profile/authors/5216312-linxian-zhutag:de.mathworks.com,2005:Question/2103062015-04-19T07:25:24Z2015-04-19T17:50:46ZObtaning values and plotting Lennard-Jones function<p>I need to evaluate the below function which is the Lennard-Jones function defining the van der Waals forces between atoms. The function and the plot it must give are attached. Sigma and epsilon are constants in the function. I tried to write the code for it in couple of different forms and also tried to do it in MS Excel but all of those gave a curve that resembles a saturation curve. Any help would be very appreciated.</p>Ugur Batirhttp://de.mathworks.com/matlabcentral/profile/authors/6348799-ugur-batirtag:de.mathworks.com,2005:Question/2103342015-04-19T11:23:16Z2015-04-19T17:43:00ZI am getting noise at the output of MATLAB SCRIPT.<p>I need to plot the individual flow to total flow. suppose, i have taken the flow2_vs_totalflow and then i am getting the disturbances in MATLAB script.so, how to remove disturbances in the output graph and is there any filter to use for getting accurate curve.</p>nani kalyanhttp://de.mathworks.com/matlabcentral/profile/authors/6430489-nani-kalyantag:de.mathworks.com,2005:Question/2103752015-04-19T17:36:48Z2015-04-19T21:46:05ZActually i am using this code to match the feature of the 1st frame by storing in the array and then matched with the next frame. But I am getting these errors. Please help me, what modification do I have to do to the following code. Please help.<p>%% The Code %%
function s=surfMatch2(str,name,st,en)
matches_arr=[];
total=0;
unmatches_arr=[];
unmatch_feature=[];</p><pre> for num_images=st:en-1
disp(['Processing frame:',num2str(num_images),' and ',num2str(num_images+1)]);
path1=[str,'\',name,'_',num2str(num_images),'.bmp'];
path2=[str,'\',name,'_',num2str(num_images+1),'.bmp'];
I1=imread(path1);
I2=imread(path2);
img_arr1=rgb2gray(I1);
img_arr2=rgb2gray(I2);
f1= detectSURFFeatures(img_arr1);
f2= detectSURFFeatures(img_arr2);
matchcount=0;
h=length(f1);
g=length(f2);
disp(['No. of features in frame ',num2str(num_images),'=',num2str(h)]);</pre><pre> disp(['No. of features in frame ',num2str(num_images+1),'=',num2str(g)]);
[features1, validf1] = extractFeatures(img_arr1, f1.selectStrongest(45));
[features2, validf2] = extractFeatures(img_arr2, f2.selectStrongest(45));
%strongestPoints = validf1.selectStrongest(1000);
%no_of_features1=length(strongestPoints);
unmatch_feature=horzcat(unmatch_feature,features1);
%disp(unmatch_feature);
%disp(['No. of matching features in block ',num2str(num_images),'=',num2str(no_of_features1)]);
indexPairs = matchFeatures(unmatch_feature, features2);
matchedIm1 = validf1(indexPairs(:,1),:);
matchedIm2 = validf2(indexPairs(:,2),:);
% matchedIm3 = validf2(indexPairs(:,3),:);</pre><pre> no_of_matchedPts=size(matchedIm1,1);
%[features3, validf3] = extractFeatures(indexPairs,1);
% m3 = matchFeatures(features3, features2);
%m4=length(m3);</pre><pre> disp(['No. of matching features in block ',num2str(num_images),',',num2str(num_images+1),'=',num2str(no_of_matchedPts)]);
matchcount=matchcount+no_of_matchedPts;
disp(['No. of overall matching features in block ','=',num2str(matchcount)]);
matches_arr=[matches_arr,no_of_matchedPts];
disp('No. of matching features of two consecutive frames stored in array ');
disp(matches_arr);
unmatchedIdx1 = true(1, size(features1, 1));
unmatchedIdx1(indexPairs(:, 1)) = false;
unmatchedFeatures1 = features1(unmatchedIdx1, :);
no_of_unmatched=length(unmatchedFeatures1);
disp(['The number of unmatched features of frame ',num2str(num_images),'=',num2str(no_of_unmatched)]);
unmatchedIdx2 = true(1, size(features2, 1));
unmatchedIdx2(indexPairs(:, 1)) = false;
unmatchedFeatures2 = features2(unmatchedIdx2, :);
no_of_unmatched1=length(unmatchedFeatures2);
disp(['The number of unmatched features of frame ',num2str(num_images+1),'=',num2str(no_of_unmatched1)]);
totalunmatchedpoints=no_of_unmatched1+no_of_unmatched;
disp(['No. of unmatching features in block ',num2str(num_images),',',num2str(num_images+1),'=',num2str(totalunmatchedpoints)]);
unmatches_arr=[unmatches_arr,totalunmatchedpoints];
disp('No. of unmatched features stored in array of the two consecutive frames');
disp(unmatches_arr);
% total=total+matchedIm1+unmatchedIdx1;
%t=length(total);
%disp((indexPairs));
%[tform, inlierf1, inlierf2] = estimateGeometricTransform(matchedIm1, matchedIm2, 'affine');
figure;
showMatchedFeatures(I1,I2, matchedIm1, matchedIm2,'montage');
%g=length(h);
%disp(['No. of matching features in block ','=',g]);
end
end</pre><p>After running the code, the error output</p><img src = "/matlabcentral/answers/uploaded_files/29349/Untitled.png">Sourav Dashttp://de.mathworks.com/matlabcentral/profile/authors/6388817-sourav-dastag:de.mathworks.com,2005:Question/1830962015-03-14T06:58:01Z2015-04-19T17:24:38ZHelp regarding Image Segmentation of B/W Image!!<p>Hello!
I am working on a project titled 'Yarn Hairiness determination using Image Processing'. The steps involved are- Image processing and Image analysis. In the processing, I converted the image to B/W. After that I am suppose to segment the core yarn from the its protruding fibres. I am stuck here. I have attached the the picture below. It would be a big help!</p>Samkit Muttahttp://de.mathworks.com/matlabcentral/profile/authors/6253158-samkit-mutta