http://www.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2017-01-21T19:40:05Ztag:www.mathworks.com,2005:Question/3213852017-01-21T18:06:23Z2017-01-21T19:40:05Zcreate live script R2015a<p>Hi,
I want to create a live script so i can put some images in my editor window while i'm coding. It's supposed that my version can work with this but when I go to Home-New->.. there is no "Live script", so i tried with command prompt 'edit name.mlx' and then select create name.mlx but this retrieve me "Error reloading name.mlx".
Which can be the causes of this?
Do i need to reinstall?
Thanks</p>Libros Construccionhttp://www.mathworks.com/matlabcentral/profile/authors/9336281-libros-construcciontag:www.mathworks.com,2005:Question/3213052017-01-20T21:43:53Z2017-01-21T19:37:00ZHow to read multiple jpg images in matlab<p>i have 250 jpg images stored at in_dir = 'C:\Users\DJDJ\Desktop\pic';</p><p>these pictures are arranged as following and named : image1 , image2, image3.....image250</p><p>I want to read all these images and processing them starting by image1 after processing go to process image2 .and after image3.to..image250</p><p>then saved the resultant images after preproceesing in a specific file,for example at
out_dir = 'C:\Users\DJDJ\Desktop\pic output';.</p><p>How can i do this in matlab?</p><p>thank you in advance</p>djamaleddine djeldjlihttp://www.mathworks.com/matlabcentral/profile/authors/8944072-djamaleddine-djeldjlitag:www.mathworks.com,2005:Question/3213362017-01-21T06:33:42Z2017-01-21T19:33:51ZTrying to extract data from a csv file<p>Hello, I'd like to create a data logging system that extracts a certain cell range from an excel file, but I'm running into trouble.</p><p>Here is my very simple code:</p><pre class="language-matlab">filename = 'mydata.csv';
M = csvread('mydata.csv',3,4,[3,4,22,4])
</pre><p>Here is the error I am getting:</p><pre class="language-matlab">Error using dlmread (line 147)
Mismatch between file and format string.
Trouble reading 'Numeric' field from file (row number 1,
field number 7) ==> hours instead of 24,\n
</pre><pre class="language-matlab">Error in csvread (line 50)
m=dlmread(filename, ',', r, c, rng);
</pre><pre class="language-matlab">Error in Untitled (line 2)
M = csvread('lap shear data.csv',3,4,[3,4,22,4])
</pre><p>Does anyone know why this is happening? I just want to extract the column that has the numbers (Column 5).. Not sure why it's trying to read the next one over.</p><p>Thanks in advance!!</p>Anahita Mahmoodihttp://www.mathworks.com/matlabcentral/profile/authors/6643168-anahita-mahmooditag:www.mathworks.com,2005:Question/3212082017-01-20T09:46:56Z2017-01-21T19:30:49ZBest CPU for neural networks: 4 fast cores vs 6 slow cores<p>Long story short:</p><p>for an intensive use of neural network toolbox in matlab what is best choice?</p><p>1. Intel Core i7 7700k, 4 cores @4.5ghz</p><p>2. Intel Core i7 6800k, 6 cores @3.6ghz</p><p>Thanks</p>Robertohttp://www.mathworks.com/matlabcentral/profile/authors/5700959-robertotag:www.mathworks.com,2005:Question/2640522016-01-17T10:49:04Z2017-01-21T19:22:20Zhow to convert .mat to .dcm<p>Hi
I have a 128x128 matrix
I want to convert it to .dcm file
What matlab comment I should use</p>Meggie Hwanghttp://www.mathworks.com/matlabcentral/profile/authors/7520415-meggie-hwangtag:www.mathworks.com,2005:Question/3213892017-01-21T18:43:10Z2017-01-21T19:27:19ZHow do I substitute vorticity components for velocity component derivatives within the Navier-Stokes equations in mupad or symbolic editor?<p>I am working on a form of the Navier-Stokes equations and am converting them to the vorticity-velocity form by taking the curl the momentum equations. Having taken the curl in mupad successfully I would now like to substitute the velocity component derivatives for the vorticity vector components. For example within the long equation i would like to find the combination [d(Uz)/dy-d(Uy)/dz] and substitute Wx in its place. Is there a way to do this in mupad or will it have to be done manually?</p><p>I tried using subsex( Equation, [d(Uz)/dy-d(Uy)/dz=Wx, d(Ux)/dz-d(Uz)/dx=Wy, d(Uy)/dx-d(Ux)/dy=Wz] ).
It did nothing, presumably because the items in the larger equation are not grouped that way...</p><p>Below are my mupad inputs:</p><p>reset()</p><p>ux:=Ux(x,y,z,t)</p><p>uy:=Uy(x,y,z,t)</p><p>uz:=Uz(x,y,z,t)</p><p>rho:=`ρ`</p><p>p:=P(x,y,z)</p><p>mu:=`μ`</p><p>phi:=`φ`(x,y,z)</p><p>uxdx:=diff(ux, x)</p><p>uydx:=diff(uy,x)</p><p>uzdx:=diff(uz,x)</p><p>uxdy:=diff(ux,y)</p><p>uydy:=diff(uy,y)</p><p>uzdy:=diff(uz,y)</p><p>uxdz:=diff(ux,z)</p><p>uydz:=diff(uy,z)</p><p>uzdz:=diff(uz,z)</p><p>divu:=uxdx+uydy+uzdz</p><p>DuxDt:=diff(ux,t)+ux*uxdx+uy*uxdy+uz*uxdz</p><p>DuyDt:=diff(uy,t)+ux*uydx+uy*uydy+uz*uydz</p><p>DuzDt:=diff(uz,t)+ux*uzdx+uy*uzdy+uz*uzdz</p><p>nu:=`ν`</p><p>v:=Vt(x,y,z,t)</p><p>assume(rho>0)</p><p>assume(RO>r>IR>0)</p><p>assume(1>=n>=0)</p><p>assume(0.1>=ecc>0)</p><p>Continuity:=simplify(combine(eval(divu=0)))</p><p>diff(v*(uxdx+uxdy+uxdz+uxdx+uydx+uzdx),x)</p><p>Xaxis:=simplify(combine(eval(DuxDt=-1/rho*diff(p,x)+nu*(diff(uxdx,x)+diff(uxdy,y)+diff(uxdz,z)) + diff(v*(uxdx+uxdy+uxdz+uxdx+uydx+uzdx),x) + diff(v*(uxdx+uxdy+uxdz+uxdx+uydx+uzdx),y) + diff(v*(uxdx+uxdy+uxdz+uxdx+uydx+uzdx),z) )))</p><p>Yaxis:=simplify(combine(eval(DuyDt=-1/rho*diff(p,y)+nu*(diff(uydx,x)+diff(uydy,y)+diff(uydz,z)) + diff(v*(uydx+uydy+uydz+uxdy+uydy+uzdy),x) + diff(v*(uydx+uydy+uydz+uxdy+uydy+uzdy),y) + diff(v*(uydx+uydy+uydz+uxdy+uydy+uzdy),z) )))</p><p>Zaxis:=simplify(combine(eval(DuzDt=-1/rho*diff(p,z)+nu*(diff(uzdx,x)+diff(uzdy,y)+diff(uzdz,z)) + diff(v*(uzdx+uzdy+uzdz+uxdz+uydz+uzdz),x) + diff(v*(uzdx+uzdy+uzdz+uxdz+uydz+uzdz),y) + diff(v*(uzdx+uzdy+uzdz+uxdz+uydz+uzdz),z) )))</p><p>Xvort:=simplify(combine(eval( subsex( diff(Zaxis,y)-diff(Yaxis,z) ,[diff(uz,y)-diff(uy,z)=Wx(x,y,z,t),uxdz-uzdx=Wy(x,y,z,t),uydx-uxdy=Wz(x,y,z,t)]) )))</p>Neal Morganhttp://www.mathworks.com/matlabcentral/profile/authors/2994476-neal-morgantag:www.mathworks.com,2005:Question/3213322017-01-21T06:06:15Z2017-01-21T19:12:22ZSyntax in sysic: Can an array be assigned as an argument in sysic?<p>I've been getting a problem with the sysic syntax
I am changing the number and the combination of outputs when using sysic as below.</p><pre class="language-matlab">for i=1:10
Elements=nchoosek(n,i);
numComb=size(Elements,1);
for j=1:numComb
element=Elements(j,:);
try
Ws=sel(WsAll,element,element);
systemnames = ' P Ws Wt Wn';
inputvar = '[ dist{4}; noise{12}; control{4} ]';
outputvar = '[ Ws; Wt; -P-Wn]'; % Ws=7, Wt=4
input_to_P = '[ control + dist ]';
input_to_Ws = '[ P(element) ) ]';
input_to_Wt = '[ control ]';
input_to_Wn = '[ noise ]';
sysoutname = 'G';
cleanupsysic = 'yes';
sysic;
[K, CL, gamma] = hinfsyn(G,12,4,1,10,0.01,2);
catch ME
fprintf('%s\n',ME.message);
continue
end
combinations(count,:)=element;
gammas(count,:)=gamma;
count=count+1;
end
end
</pre><p>However, matlab does not accept a variable in sysic syntax.
The error occurs at</p><pre class="language-matlab">input_to_Ws = '[ P(element) ) ]';
</pre><p>is there any way that I can assign a variable in sysic?
Any help would be appriciated</p>Kandai Watanabehttp://www.mathworks.com/matlabcentral/profile/authors/6429681-kandai-watanabetag:www.mathworks.com,2005:Question/3213142017-01-20T22:52:49Z2017-01-21T19:06:09ZVariable not found in parfor loop<p>If I run the script:</p><pre class="language-matlab">z=1:1000;
</pre><pre class="language-matlab">parfor i=1:numel(z)
zfun(z(i))
end
</pre><p>which calls the function:</p><pre class="language-matlab">function zfun(z)
</pre><pre class="language-matlab">for j=1:50
for k=1:100
myz=z*10+myz*k;
end
end
</pre><pre class="language-matlab">save(fullfile('filepath', num2str(myz)), 'myz');
</pre><pre class="language-matlab">end
</pre><p>I get an error of <b>Undefined function or variable 'myz'</b> for the save command.</p><p>Any ideas how to fix this?</p>JohnDylonhttp://www.mathworks.com/matlabcentral/profile/authors/3477878-johndylontag:www.mathworks.com,2005:Question/3213922017-01-21T18:49:34Z2017-01-21T18:49:34ZProblem with grid spacing in pdetool<p>In pdetool, I've a problem with Options>Grid Spacing when I try to change the linear spacing on x (or the y) axis. The strange thing is that two days ago it work perfectly. I try to uninstall and re-download the tool, but it don't work.
Matlab version R2016b.</p>Alessandro Olivierihttp://www.mathworks.com/matlabcentral/profile/authors/6599721-alessandro-olivieritag:www.mathworks.com,2005:Question/449812012-07-31T20:08:26Z2017-01-21T18:49:12Zunique function in matlab<p>Hi guys</p><p>In the version of R2012a, the unique function has a 'stable' property. Please see
the link:</p><p><a href = "http://www.mathworks.com/help/techdoc/ref/unique.html">http://www.mathworks.com/help/techdoc/ref/unique.html</a></p><p>A = [9 2 9 5];
[C, ia, ic] = unique(A,'stable')</p><p>C =</p><pre> 9 2 5</pre><p>ia =</p><pre> 1
2
4</pre><p>ic =</p><pre> 1
2
1
3</pre><p>But my matlab version is R2010a, it seems that the unique function in R2010a does not support 'stable'. How can I get the stable result?</p><p>Thanks,</p>zhanghttp://www.mathworks.com/matlabcentral/profile/authors/1170109-zhangtag:www.mathworks.com,2005:Question/3213822017-01-21T17:20:34Z2017-01-21T18:46:51ZCreating a hex array with 4 digit blocks from an array of integers<p>I am using R2013 and need to convert a large decimal array into hex stings.</p><p>The decimal numbers can be any positive integer, and I need to convert each number, then display each as a minimum two byte string with preceding zeros (with more bytes shown as the number increases).</p><p>e.g. decimal "1" should show up as '0x0001',</p><p>decimal "69876" should show up as '0x0001 0x10F4'</p><p>I created a rather cumbersome loop that does this perfectly, but with large arrays it takes too long.</p><p>I can get part way to a non-loop implementation with this code:</p><pre class="language-matlab">DecArray = [1 2 4 69876];
cellstr(dec2hex(reshape(DecArray,[],1), 4));
ans =
'00001'
'00002'
'00004'
'110F4'
</pre><p>But as you see the outputs</p><p>1) always have the same number of digits, and</p><p>2) aren't broken into 2 Byte blocks</p><p>Is there any way to go from these results to the ones I described earlier without another loop?</p>Arthttp://www.mathworks.com/matlabcentral/profile/authors/2943513-arttag:www.mathworks.com,2005:Question/3213912017-01-21T18:45:57Z2017-01-21T18:45:57ZMATLAB not starting after installation in Ubuntu 14.04<p>I have installed matlab properly in ubuntu 14.04. Everything went perfectly but it does not start after installation If I click on MATLAB icon nothing happens it stays right there
matlab ubuntu</p>Ahmed Khanhttp://www.mathworks.com/matlabcentral/profile/authors/9566645-ahmed-khantag:www.mathworks.com,2005:Question/3213902017-01-21T18:44:42Z2017-01-21T18:44:42ZIs their a support package for NI myRio 1900 ?<p>"Data Acquisition Toolbox™ Support Package for National Instruments® NI-DAQmx Devices provides support for CompactDAQ, X-Series, M-Series, E-Series, USB, myDAQ, ELVIS II, <b>and many other types</b> of data acquisition hardware from National Instruments through MATLAB® and Data Acquisition Toolbox."</p><p>Does the Data Acquisition Toolbox™ Supports NI myRio 1900 ?</p>Nouaman Abdelkhalekhttp://www.mathworks.com/matlabcentral/profile/authors/6925448-nouaman-abdelkhalektag:www.mathworks.com,2005:Question/3213872017-01-21T18:38:31Z2017-01-21T18:43:38ZWhat is MATLAB convention for the direction of normal vector of a triangulated mesh?<p>By using the function <i>triangulation</i>, you can have a triangulated mesh. Then by function <i>faceNormal(tr)</i> you can get the normal vector on each triangle. What is the convention for the direction of normal vectors (inward / outward)? How MATLAB manages to make them toward a consistent direction for a nice surface such as a sphere? Is there any predefined (in MATLAB) relationship between the direction of the normal vector and curvature of the surface?
Thanks.</p>Alireza Dastanhttp://www.mathworks.com/matlabcentral/profile/authors/7288971-alireza-dastantag:www.mathworks.com,2005:Question/3213882017-01-21T18:41:32Z2017-01-21T18:41:32ZVoxel Image intensity inCT images<p>Hello,
i have CT images and i want to get the Voxel Intensity at I(x,y,z), please ca any one explain to me how i can get this intensity.
Thank you
Lafi</p>Lafi Raedhttp://www.mathworks.com/matlabcentral/profile/authors/8075330-lafi-raedtag:www.mathworks.com,2005:Question/3213862017-01-21T18:15:22Z2017-01-21T18:38:46ZMerge text and numeric formats to double<p>Does anyone know how to combine text and numeric formats into double or matrix form?</p><p>I have two data sets:</p><p>A is a 1x500 table.
A 1x5 example of data in the following format:</p><pre class="language-matlab">A={'aapl' 'abbv' 'abc' 'abt' 'ace'};
A=cell2table(A);
</pre><p>B is a 6322 x 500 table.
A 3x5 example in following format:</p><pre class="language-matlab">B={12.4949 6.96103 NaN 7.03814 13.0399...
12.5195 7.02181 NaN 7.39418 12.7675...
12.7307 7.21876 NaN 7.75691 12.6901};
B=cell2table(B);
</pre><p>Would like to concatenate A to B, as C, in a double format for analysis and comparisons so C would look like</p><pre class="language-matlab">C=
aapl abbv abc abt ace
12.4949 6.96103 NaN 7.03814 13.0399
12.5195 7.02181 NaN 7.39418 12.7675
12.7307 7.21876 NaN 7.75691 12.6901
</pre><p>I've tried concantenating cells</p><pre> A=table2cell(A);
B= table2cell(B);
C=[A;B];</pre><pre> and I get following error...
"All contents of the input cell array must be of the same data type."</pre><p>Tried converting B to double, A to categorical then concantenating</p><pre class="language-matlab">A=categorical(A);
B= table2array(B);
C=[A;B];
</pre><pre> and I get following error...
"Can not concatenate a double array and a categorical array."</pre><p>Tried many other combos but nothing seems to work?
Thank you for any suggestions.</p><p>AR</p>ARhttp://www.mathworks.com/matlabcentral/profile/authors/7097422-artag:www.mathworks.com,2005:Question/3213582017-01-21T12:12:24Z2017-01-21T18:19:18ZHow to sum points in an 2-D area efficiently?<p>I have an NxN array which is modelling an array of sensors and I have many objects that lie on this array. Each object belongs to a cluster. The objects may be anywhere on the array (e.g. (1.212, 4.567) ) but the array has a spatial accuracy that is unity. So all the objects in each individual array sensor needs to be accumulated. The below image helps visualise my problem.</p><img src = "/matlabcentral/answers/uploaded_files/68021/Screen%20Shot%202017-01-21%20at%2011.43.35.png"><p>Currently I have each cluster in a cell. And each cell contains two vectors with the x and y co-ordinates of the objects that belong to that cluster. The function below is a solution to my problem but it is very inefficient and is not practical. I was wondering if there are more efficient solutions and whether I am being naive. I am open to changing the structure of the my variables but each cluster has a different number of objects so I decided cells were appropriate.</p><pre> function [ Z ] = sumSensor( clusters, num_of_clusters, N )
% Inputs: clusters is a struct with the vectors clusters.myobj.x and clusters.myobj.y representing the co-ordinates of the objects on the array
Z = zeros(N,N);
% For every sensor...
for i = 1:N
for j = 1:N
% And every cluster...
for k = 1:num_of_clusters
% Search for every object on the sensor and accumulate them
Z(i,j) = Z(i,j) + sum((floor(clusters{k}.myobj.x)==i) & (floor(clusters{k}.myobj.y)==j));
end
end
end
end</pre><p>An test case could be:</p><pre> N = 32;
num_of_clusters = 5;</pre><pre> clusters = cell(num_of_clusters,1);</pre><pre> for i = 1:num_of_clusters
clusters{i} = struct();</pre><pre> % Random integer between 10000 and 110000
randLength = round(10E4+10E5*rand);</pre><pre> % Random co-ordinates between 1 and N+1
clusters{i}.myobj.x = 1 + N*rand(1,randLength);
clusters{i}.myobj.y = 1 + N*rand(1,randLength);
end</pre><pre> Z = sumSensor(clusters, 2, N);</pre>Ahmad Monirihttp://www.mathworks.com/matlabcentral/profile/authors/6826425-ahmad-moniritag:www.mathworks.com,2005:Question/259702012-01-12T19:51:05Z2017-01-21T18:15:16ZPrinting values to the command window<p>how does one print a value of a variable to the command window?</p>Isabellahttp://www.mathworks.com/matlabcentral/profile/authors/2562712-isabellatag:www.mathworks.com,2005:Question/3213742017-01-21T15:35:09Z2017-01-21T18:11:35ZHow to get image loaded in axes?<p>hi,</p><p>i want to get the image loaded in an axis. that axis will be loaded by different image one at a time. why? because that axis will show the converted image (like grayscale, image segmentation, canny edge, and clustering). so instead of using imshow(...) for every conversion. i will be using a push button to open that image in a new window to avoid multiple windows opend and to have an option to display it.</p><p>so im not sure what will i use to store the current image in that axis and open it in a new window.</p>Jepher John Changhttp://www.mathworks.com/matlabcentral/profile/authors/9473802-jepher-john-changtag:www.mathworks.com,2005:Question/3213532017-01-21T10:49:33Z2017-01-21T18:05:26ZSort alphabetically without using sort<p>Is it possible to sort alphabetically without using sort? If so, how can be do it?</p>Cesc Sebashttp://www.mathworks.com/matlabcentral/profile/authors/9566253-cesc-sebastag:www.mathworks.com,2005:Question/3213842017-01-21T17:40:28Z2017-01-21T18:01:58Zsave in excel file inside a for loop<p>hi
i want to save the values of a vector in a xls file. The value s change
inside a for loop...
the variable is avg_rayleigh</p><p>clc</p><p>syms k
s=sqrt(2/pi);
m=2;
w=4.527;
S=1;
sigma=1.42558;
s_chi=0.42552;
freq=[100:100:700]'</p><p>for i=100:100:700
freq=i;
f=i*1e6;</p><pre> [hm,P,er,k0,beta,er_eff,L]=parameter(f);</pre><p>r=sqrt(er_eff)./er;
theta=2*pi/5;</p><p>phi=3*pi/7;
%phid=acosd(r.*sin(theta))
distr='Rayleigh'
%coifficients
[d1,d2]=coifp(k0,beta,L,er_eff,er,theta,phi);</p><p>d=d2;</p><p>if strcmp(distr,'Rayleigh')
y=(sqrt(2/pi)*P*s*d)*1e3;</p><p>avg_rayleigh=[freq y]</p><p>%xlswrite('resultsmean.xls',avg_rayleigh,'sheet1','A1','B1')
%xlswrite('out.xls',freq','sheet1','A1')
%xlswrite('out.xls',avg_rayleigh(:,1),'sheet1','A1')
%xlswrite('out.xls',avg_rayleigh(:,2),'sheet1','B1')</p><p>elseif strcmp(distr,'chi')</p><p>y=((15/8)*sqrt(2/pi)*s_chi*d*P)*1e3;</p><p>avg_chi=[freq y];</p><p>elseif strcmp(distr,'nakagami')
y=((2/pi)*P*d*sqrt(w/m)*(gamma(m+1/2)/gamma(m)))*1e3;</p><p>avg_nakagami=[freq(i) y]</p><p>elseif strcmp(distr,'rician')</p><p>A=S/(sqrt(2)*sigma);
I=(2*sqrt(2)/pi)*P*d*sigma*exp(-S^2/(2*sigma^2));
r=factorial(k);
y=(I*vpa(symsum( A^(2*k)*gamma(k+3/2)/(r^2),0,inf),4))*1e3;</p><pre> avg_rician=[freq y]; </pre><p>end
end</p>george veropouloshttp://www.mathworks.com/matlabcentral/profile/authors/1021212-george-veropoulostag:www.mathworks.com,2005:Question/731052013-04-22T14:29:26Z2017-01-21T17:48:24Zhow to produce edge detected image <pre> using the Laplacian of the Gaussian or Sobel filters, of user-specified size and parameters where applicable. how to apply filters of varying size </pre>nita ahmetihttp://www.mathworks.com/matlabcentral/profile/authors/4254871-nita-ahmetitag:www.mathworks.com,2005:Question/3213832017-01-21T17:33:41Z2017-01-21T17:39:30Zi want one example about edge detection algorithm<p>I = imread('circuit.tif');
imshow(I)
BW1 = edge(I,'Canny');</p>Mohamed Osmanhttp://www.mathworks.com/matlabcentral/profile/authors/8984950-mohamed-osmantag:www.mathworks.com,2005:Question/3213282017-01-21T05:14:33Z2017-01-21T17:34:57ZSave new name in file .mat and loop new name <p>This is my code</p><pre class="language-matlab">function [] = AREAPICTURE (BW)
BWAREA = bwarea(BW);
save('AREA.mat','BWAREA');
end
</pre><p>I want have save new name of <tt>BWAREA</tt> sample <tt>BWAREA001</tt> ,|BWAREA002|
loop new name and save in file .mat or csv file.</p>Adisorn Phanukthonghttp://www.mathworks.com/matlabcentral/profile/authors/6937939-adisorn-phanukthongtag:www.mathworks.com,2005:Question/3213812017-01-21T16:52:00Z2017-01-21T17:10:03ZHow can i create an odometer counter<p>I need your help for solving a problem.
I want to create a loop, each time giving the row A (for n cells).
ex. for n=4
A=[0 0 0 0]
A=[0 0 0 1]
A=[0 0 0 2]
...
A=[0 0 0 9]
A=[0 0 1 0]
A=[0 0 1 1]
...
A=[9 9 9 9]
It is something like an odometer or counter.</p><p>Thank you,</p>Georgehttp://www.mathworks.com/matlabcentral/profile/authors/1540844-georgetag:www.mathworks.com,2005:Question/3213482017-01-21T10:22:48Z2017-01-21T16:47:01Zhow can i handle indexoutofbounds error (Attempted to access c1(63,65); index out of bounds because size(c1)=[64,64])<pre class="language-matlab">A=imread('cameraman.tif');
[x,y]=size(A);
c1=imcrop(A,[1 1 x/4-1 y/4-1]);
c2=imcrop(A,[y/4-1 1 x/4-1 y/4-1]);
c3=imcrop(A,[y/2-1 1 x/4-1 y/4-1]);
c4=imcrop(A,[y/1.33-1 1 x/4-1 y/4-1]);
subplot(221), imshow(c1) , subplot(222) , imshow(c2) ,subplot(223) , imshow(c3) ,subplot(224) , imshow(c4)
figure, imshow(A)
[a,b]=size(c1);
for i=0:a
for j=0:b
new=0;
if (c1(a-1,b+1)>c1(a,b))
new=new+1;
end
if (c1(a,b+1)>c1(a,b))
new=new+2;
end
if(c1(a+1,b+1)>c1(a,b))
new=new+4;
end
if(c1(a+1,b)>c1(a,b))
new=new+8;
end
if(c1(a+1,b-1)>c1(a,b))
new=new+16;
end
if(c1(a,b-1)>c1(a,b))
new=new+32;
end
if(c1(a-1,b-1)>c1(a,b))
new=new+64;
end
if(c1(a-1,b)>c1(a,b))
new=new+128;
end
c1(a,b)=new(a,b);
end
end
</pre>Faisal Javedhttp://www.mathworks.com/matlabcentral/profile/authors/8505646-faisal-javedtag:www.mathworks.com,2005:Question/3213802017-01-21T16:37:19Z2017-01-21T16:37:19Zhow to import solidworks CAD model into simulink 3d animation?<p>I have made a CAD model in Solid Works but I don't know how to import it in MATLAB Simulink 3D pls Help.</p>Rachit Ahujahttp://www.mathworks.com/matlabcentral/profile/authors/9560726-rachit-ahujatag:www.mathworks.com,2005:Question/3213792017-01-21T16:30:28Z2017-01-21T16:37:11Zactually in this code i want use local mean estimator can any one help me how to use local mean estimator and get proper mean value<p>clear;
close all;
I = imread('G:\10image/human.jpg');
I=rgb2gray(I);
I = double(I);</p><p>%// Adjust intensities in image I to range from 0 to -3
I = I - min(I(:));
I = I / max(I(:));</p><p>%// Add noise to image
v = var(I(:))/sqrt(5);
X = imnoise(I, 'gaussian', 0, v);
%mean1 = mean2(X);
%std1 = std2(X);
%gi = (double(X)-mean1)*(0.001/std1);
%z = X-mean2(X)/std2(X);
[M,N]=size(X);
z = 2.576;
%z_(alpha/2) = 2.5;
E = z(std2(X)/sqrt(M*N));
Ns=3; % 5*5 support region
u=0.001; % step size
Y=zeros(M,N); % predicted image
%avg3 = ones(3)/9;
%Y(1:Ns,1:Ns)=I(1:Ns,1:Ns);
D=zeros(M,N);
%D=(E(X(M,N)));
%D(2:M,2:N)=I(2:M,2:N); % D is shifted version of X
e=zeros(M,N); % error matrix
W=zeros(Ns,Ns); % weight matrix</p><p>for m=1+floor(Ns/2):M-floor(Ns/2)
for n=1+floor(Ns/2):N-floor(Ns/2)
for l=1:Ns
for k=1:Ns
Y(m,n)= Y(m,n)+W(l,k)*X(m-floor(Ns/2)+(l-1),n-floor(Ns/2)+(k-1));
%%weiner filter
%D(m,n) = mean(X(m-floor(Ns/2)+(l-1),n-floor(Ns/2))+(k-1));
%D(m,n) = conv2(X(m-floor(Ns/2)+(l-1),n-floor(Ns/2)+(k-1)),ones(3)/9,'same');
%D(m,n) = sum(temp(:),ones(3)/9,'same');
%ts = tinv([0.025 0.975],length(X)-1);
%E(m,n)=X.*std(m,n)/sqrt(m,n);
D(m,n)=(E(X(m-floor(Ns/2)+l-1,n-floor(Ns/2)+k-1)));
%D(m,n)= mean2(gi);
%D(m,n)=sum(X(m-floor(Ns/2)+(l-1),n-floor(Ns/2)+(k-1))/length(X(m-floor(Ns/2)+(l-1),n-floor(Ns/2)+(k-1))));
%D(m,n)=sum(X(m-floor(Ns/2)+(l-1),n-floor(Ns/2)+(k-1))-mean(m-floor(Ns/2)+(l-1),n-floor(Ns/2)+(k-1)).^2)/(length(X(m-floor(Ns/2)+(l-1),n-floor(Ns/2)+(k-1))-1));
e(m,n)=D(m,n)-Y(m,n);
W(l,k)=W(l,k)+u*e(m,n)*X(m-floor(Ns/2)+(l-1),n-floor(Ns/2)+(k-1));</p><pre> %E(i)=ts*std(X(m,n))/sqrt(length(X(m,n)));
end
end
end
end</pre><p>subplot(231)
imshow(I); title('original image I')
subplot(232)
imshow(X); title('noisy image X')
subplot(233)
imshow(D); title('D')
subplot(234)
imshow(Y); title('Y')
subplot(235)
imshow(e); title('e')</p><p>org=I(1+floor(Ns/2):M-floor(Ns/2), 1+floor(Ns/2):N-floor(Ns/2));
nos=X(1+floor(Ns/2):M-floor(Ns/2), 1+floor(Ns/2):N-floor(Ns/2));
fil=Y(1+floor(Ns/2):M-floor(Ns/2), 1+floor(Ns/2):N-floor(Ns/2));</p><p>%parameter 1
PSNRpre = PeakSignaltoNoiseRatio(org, nos)
PSNRpos = PeakSignaltoNoiseRatio(org, fil)</p><p>%parameter 1
MSEpre = MeanSquareError(org, nos)
MSEpos = MeanSquareError(org, fil)</p><p>%parameter 1
NKpre = corr2(org, nos)
NKpos = corr2(org, fil)
%NKpre = NormalizedCrossCorrelation(org, nos)
%NKpos = NormalizedCrossCorrelation(org, fil)</p>jadav singhhttp://www.mathworks.com/matlabcentral/profile/authors/8498243-jadav-singhtag:www.mathworks.com,2005:Question/3195092017-01-08T15:19:58Z2017-01-21T16:37:04ZUndefined operator '*' for input arguments of type 'cell'. Error in eg9copy (line 23) RBV=((Vc*l1+Vd*((l-l2)/l)))<p>%%This program can be used to calculate the deameter of a shaft with two
%%pulleys</p><p>%% Taking inputs for the variables of the pulleys and the shaft</p><p>clc
a=42;
%allowable shear stress</p><p>pi=3.14;</p><p>b=63; %allowable working stress</p><p>l= inputdlg('enter the span of the shaft l=');</p><p>d1= inputdlg('enter the diameter of the first pulley from the left d1(in m)=');</p><p>l1= inputdlg('enter the distance of the first pulley from the left l1(in m)=');</p><p>d1= inputdlg('enter the diameter of the second pulley from the left d2(in m)=');</p><p>l2= inputdlg('enter the distance of the second pulley from the right l2(in m)=');</p><p>Vc= inputdlg('enter the vertical load on first pulley Vc=');</p><p>Hc= inputdlg('enter the horizontal load on first pulley Hc=');</p><p>Vd= inputdlg('enter the vertical load on second pulley Vd=');</p><p>Hd= inputdlg('enter the horizontal load on second pulley Hd=');</p><p>%let RA and RB be the reactions at the bearing positions</p><p>%% For the vertical loading</p><p>RBV=((Vc*l1+Vd*(l-l2)/l))</p><p>fprintf('Vertical reaction at B=%4.2f N\n',RBV)</p><p>RAV=(Vc+Vd-RBV)</p><p>fprintf('Vertical reaction at A=%4.2f N\n',RAV)</p><p>%% For vertical bending moment</p><p>Mav=0;
Mbv=0;</p><p>Mcv=RAV*l1;</p><p>fprintf('the vertical bending moment at
C=%4.2f\n',Mcv)</p><p>Mdv=RBV*l2;</p><p>fprintf('the vertical bending moment at B=%4.2f\n',Mdv)</p><p>How can I solve this problem??</p>Rohan Maharjajnhttp://www.mathworks.com/matlabcentral/profile/authors/9283295-rohan-maharjajntag:www.mathworks.com,2005:Question/3202042017-01-12T21:14:04Z2017-01-21T16:16:03ZMoving window with cumulative sum less than a ref value and excluding certain windows<p>I have an array of 36000 cells, i want to break those arrays into windows of cumulative sum less than a reference value. and exclude few windows based on other parameters respective to this array based on index. For example A= [ 0.5 0.6 .45 .56 .056 .16 .18 .10 .15 .45 .36]; similarly other arrays of same length. Now window 1 should start with 1st value and end at sum less than 2 ( window{1} = [0.5 0.6 .45], sum = 1.55) second window has to start from 2nd value ( window{2} = [0.6 .45 .56 .056 .16], sum = 1.826). Similarly i need all possible windows for 36000 cells, while excluding those where value/sum of other arrays/windows of respective index. Index of these windows is also needed. I here wanted a moving window. Eg Index of my windows would be like [ 1 3] , [2 6], [3 9], [4 10], [5 11], [6 11], [ 7 11], [ 8 11], [9 11], [10, 11].</p><ul><li>If i don't wont to consider values in index 3,4, 8, i want to exclude windows which include these indexes.</li><li>If i want to exclude windows whose corresponding array average is less than certain value. Ex: I've another B whose size is same as A. after breaking array A into windows, average of array B windows is less than a value (20) has to be excluded.</li></ul>RANJITH REDDY KALLURIhttp://www.mathworks.com/matlabcentral/profile/authors/7505368-ranjith-reddy-kalluritag:www.mathworks.com,2005:Question/3213722017-01-21T15:06:31Z2017-01-21T16:15:29ZHello im fairly new to writting MATLAB code, I'm performing some research and having some trouble with solving an eq. This is my input non-linear equation for the program. Should I reorientate my equation in any way? And what function should be used?<p>eq_45 = ((20*B*s^4)/rm^6) + ((8*B*s^5)/(rm-rc)^2*rm^5) + (s/(rm-rc)^3)*(((B*s^4)/rm^4)-1)*(2+(s/(rm-rm)))</p>Justice Calderonhttp://www.mathworks.com/matlabcentral/profile/authors/9489715-justice-calderontag:www.mathworks.com,2005:Question/3213782017-01-21T16:12:09Z2017-01-21T16:15:17ZHow to choose Neural Network Training values<p>I am doing hand gesture recogntion for 30 different signs. I have taken 20 images for each sign (10 for training and 10 for testing). Now I have a total of 300 images both in the training and testing set.</p><p>I have taken the following values for ANN, but the recognition is not good. Please tell me how to choose the appropriate values.</p><pre class="language-matlab">net = newff(minmax(P),[no_of_images no_of_images],{'tansig','purelin'},'traingdx','learnp');
</pre><pre class="language-matlab">net.LW{2,1} = net.LW{2,1}*0.01;
net.b{2} = net.b{2}*0.01;
net.performFcn = 'sse';
net.trainParam.goal =1;
net.trainParam.show = 50;
net.trainParam.epochs = 10416;
net.trainParam.mc = 0.95;
</pre><pre class="language-matlab">[net,tr] = train(net,P,T);
</pre>AHhttp://www.mathworks.com/matlabcentral/profile/authors/6043870-ahtag:www.mathworks.com,2005:Question/3213692017-01-21T14:08:34Z2017-01-21T16:09:55ZHow to form 2-dimensional matrix<p>How to create 8 participants of an experiment(e.g. gender,age and handedness) and store the information in a 2-dimensional matrix?
I've used so far the following code. But, how can I write in a table form? Can someone help me please?Thanks.
Say participants: p = [1 1 21 1; 2 2 25 1; 3 2 19 1;4 2 23 2; 5 1 23 1].</p><pre class="language-matlab">for p = [1 1 21 1; 2 2 25 1; 3 2 19 1;
4 2 23 2; 5 1 23 1]
disp(p)
end
</pre><pre> %and I got the output:</pre><pre class="language-matlab">1
2
3
4
5
</pre><pre> 1
2
2
2
1</pre><pre> 21
25
19
23
23</pre><pre> 1
1
1
2
1</pre>Sam Johnhttp://www.mathworks.com/matlabcentral/profile/authors/9566932-sam-johntag:www.mathworks.com,2005:Question/3213552017-01-21T11:09:51Z2017-01-21T16:09:06ZIssue in recognising multiple objects in an Image<p>I have images of Apples as well as of Oranges, which I am using as training images. The test image is an image consisting of both apple and orange. I am using GIST descriptor for feature extraction. When I train the classifier using extracted features, it gives an output as apple or orange for the test image.
I have a query, as how can I make classifier recognise both of them in the test image.
I am using KNN classifier</p>Rohan Guptahttp://www.mathworks.com/matlabcentral/profile/authors/9410906-rohan-guptatag:www.mathworks.com,2005:Question/3213772017-01-21T16:09:02Z2017-01-21T16:09:02ZFile access problem in flac format<p>While working on non-intrusive load monitoring and having different files in .flac format in one folder and there name is in order class_device_region_kit_time. Actually I want to access files on basis of device and kit information from the folder and then audio read them. So I wanna know how to fix this issue after trying different things and topologies. Filename of 1 of the file is presented as example i.e. AC_Electrolux_r5_MK2_20151031065948 here I want to pick file on base of MK2 and AC. I tried audioread command but it asks for full path name but I want AC_MK2.flac basis reading of file. I will be thankful if someone can help.</p>SYED ZULQARNAIN ALI SHAHhttp://www.mathworks.com/matlabcentral/profile/authors/7324627-syed-zulqarnain-ali-shahtag:www.mathworks.com,2005:Question/3207832017-01-17T17:04:38Z2017-01-21T16:08:08ZHow to obtain samples within angular windows?<p>Hi,
Let us say I have a projectile moving around in a square environment and I want to sample all positions where the projectile has travelled within a 20 degrees angular window, as seen from a fixed point in the environment. Can anyone help me figure out how to do this? In the attached picture, the spiral is a made up path of the projectile and the red dot is the fixed point from which I want to make the angular window.</p><p>Thanks</p><img src = "/matlabcentral/answers/uploaded_files/67717/untitled.png">OHhttp://www.mathworks.com/matlabcentral/profile/authors/4264628-ohtag:www.mathworks.com,2005:Question/3194192017-01-07T15:04:58Z2017-01-21T16:07:26ZHow to extract image region within boundary<p>Hi,
I have to segment the LV from cardiac MRI. The output is an image with a boundary for the specified region (attached image).
My question is how can i get only the region within the boundary. how to set the inside of the boundary to 1 and 0 for the rest for a binary image.</p><p>Thanks in advance.</p><img src = "/matlabcentral/answers/uploaded_files/67007/Capture.PNG">Ineshttp://www.mathworks.com/matlabcentral/profile/authors/2961706-inestag:www.mathworks.com,2005:Question/2248052015-06-22T12:11:08Z2017-01-21T16:00:36ZSkin type classification and clustering<p>Hi,</p><p>i was asked to try and classify skin types according to Fitzpatrick Scale. As a first attempt, i tried doing the following:</p><p>1) Collecting L*a*b* samples (actually only the a and b components) from skin patches of different people (collectSamples.m script)
2) Finding a Gaussian Mixture Model of 6 (number of skin types) components using the EM algorithm (training.m script)
3) Given a certain skin image as input, color it according to which clusters its a*b* samples fall into and set the dominant skin type as the id of the most used color cluster (findSkinTones() function).</p><p>Fitzpatrick scale takes into consideration other things besides color, but for the moment i'd be happy to distinguish between different color clusters. I almost never programmed in Matlab before so the code is very crude (besides being unfinished).</p><p>I'm having the following problems:</p><p>a) The clusters i get from EM seem unreasonable when plotted;
b) When i try to color/cluster a given input skin image portions of the background seem to be colored too, although they should not.</p><p>I can't upload files bigger than 5 MB, so i'll just use dropbox instead: <a href = "https://www.dropbox.com/s/5ustmorfksa0hcy/Attempt%25201.rar?dl=0">sources (dropbox host)</a></p><p>P.s. I was also thinking that a better strategy could be using entropy and average color features to train a support vector machine or neural network. What do you think?</p>Adriano Romanohttp://www.mathworks.com/matlabcentral/profile/authors/6638978-adriano-romanotag:www.mathworks.com,2005:Question/3213242017-01-21T02:54:32Z2017-01-21T15:57:42ZHow do I add custom gridlines on my image?<p>So I'm trying to program an image converter and trying to get some gridlines on it.</p><pre class="language-matlab">axis equal;
imagesc(secondlevelTIFF, scale) %read matrix into figure
axis equal;
colormap(jet) %makes it into jet
axis on;
grid on;
colorbar;
temp=[[sprintf('fig%03d', i)],'.tif']; %name current figure file
fpath = [I have my path here]; %set file directory
saveas(gcf, fullfile(fpath, temp));
</pre><p>This is my current code with the 'secondlevelTIFF' being my image.
I'm trying to add custom gridlines. The image file I have is 500*500 pixels and i want gridlines at 50 and 150 pixels.
How do I add these gridlines so that they are on the top of my final image file?</p>Hosup Songhttp://www.mathworks.com/matlabcentral/profile/authors/6111579-hosup-songtag:www.mathworks.com,2005:Question/3213762017-01-21T15:57:25Z2017-01-21T15:57:25ZRead timed out error while installing MATLAB on Windows 10<p>When I try to run the matlab installer, it throws back an Extract Error saying Read timed out while downloading audiovideo_win64_1469225912.enc .
I tried cleaning up all the downloaded matlab files/settings and disabled anti-virus, downloaded Matlab again, ran the installer, and still getting the same error. Could you please help suggesting how else to fix it?</p>Roja Bhttp://www.mathworks.com/matlabcentral/profile/authors/9566478-roja-btag:www.mathworks.com,2005:Question/3199282017-01-11T06:49:29Z2017-01-21T15:53:43ZHow to do Thermal image Normalization with range 0 to 40<p>Hi all
I'm doing research about using thermal image for temperature measurement for medical purposes, I try to repeat methodology of paper "Face and eyes localization algorithm in thermal images for temperature measurement of the inner canthus of the eyes". They used Normalization of thermal image with range 0 to 40, and they got these results.</p><img src = "https://i.stack.imgur.com/0CAxx.jpg"><p>I tried the code below:</p><pre class="language-matlab">tt = imread('test.jpg');
figure, imshow(tt)
tt = double(tt);
normimg = uint8(zeros(size(tt)));
for idx = 1 : 3
chan = tt(:,:,idx);
minvalue = min(chan(:));
maxvalue = max(chan(:));
normimg(:,:,idx) = uint8((chan-minvalue)*40/(maxvalue-minvalue));
end
figure, imshow(normimg)
</pre><p>and I got different results so what I should do to get same results Thank you in advance</p><img src = "https://i.stack.imgur.com/h6nQa.jpg">Mohammed Jaddoahttp://www.mathworks.com/matlabcentral/profile/authors/8763234-mohammed-jaddoatag:www.mathworks.com,2005:Question/3211222017-01-19T17:48:44Z2017-01-21T15:51:49ZHow to change the fontname of axes labels when using the latex interpreter<p>I am using the latex interpreter for my axes labels as opposed to tex because the subscripts look a whole lot better with the latex interpreter. However, I would like the font to look like Times New Roman, as it does when specifying 'fontname' to 'Times' with the tex interpreter. I'm using Matlab 2012a.</p><p>I've done a lot of searching - I haven't been able to find a solution to either the ugly subscripts with tex that actually looks good or a way to (easily...) changing fonts with the latex interpreter. Solutions must exist somewhere, I would appreciate any insights for either of these issues!</p>Shannonhttp://www.mathworks.com/matlabcentral/profile/authors/1573782-shannontag:www.mathworks.com,2005:Question/3213752017-01-21T15:40:23Z2017-01-21T15:46:17ZHow can i display a funtion dependenet to x ? <p>Hi
How can i can i display f with values in function of x ?</p><p>L=3;</p><p>sol(1)=2;</p><p>psi=1;</p><p>f (x) = @(x) cos ( (sol(1)/L) *x)- cosh( (sol(1)/L) *x)+ psi *( sin( (sol(1)/L) *x)- sinh( (sol(1)/L) *x));</p>Mallouli Marwahttp://www.mathworks.com/matlabcentral/profile/authors/7931408-mallouli-marwatag:www.mathworks.com,2005:Question/2633992016-01-11T18:58:12Z2017-01-21T15:30:27ZA function to find peaks (brightest pixels in a grayscale image) ?<p>Hi,</p><p>Is there any function as an alternative to FastPeakFind() to find brightest pixels in a grayscale image.</p><p>The problem of the FastPeakFind() function is that it can not find peaks correctly if they are piled.
Since, FastPeakFind() function assumes that 'peaks are sparse'. So, even if we change the threshold value, this function can only detect peaks if they are separated. If there is a piled peak then this function can not show all pixels under the peak (it only shows ONE pixel for this kind of peaks.
Therefore, we can not find correct number of bright pixels at a piled peak region.</p><p>Is there any alternative to this function ?
I want to find number of brightest pixels and density of brightest regions in a grayscale image</p><p>Thanks</p>S C.Carlhttp://www.mathworks.com/matlabcentral/profile/authors/2671557-s-c-carltag:www.mathworks.com,2005:Question/3201012017-01-12T09:15:54Z2017-01-21T15:28:51Zhow can I find the centroid of an object in a image and extract a portion of it around that centre point<p>Hello, I ll b vry grateful to u if u help me find the centroid of a mango image(image also has black background). n that i need to extract a strip of mango image around centroid. if i find centroid in bw image, den how can I interrelate it with color image so as to extract its strip?
Please guide me. looking fwd to some ideas. ty</p>swathihttp://www.mathworks.com/matlabcentral/profile/authors/4716202-swathitag:www.mathworks.com,2005:Question/3213732017-01-21T15:09:16Z2017-01-21T15:25:43ZAfter segmenting, how can I do uncompleted fruit image?<p>Dear Sir,
I am doing Fruit Recognition System.Now I segmented fruit images.But I have a problem.Some segmented fruits are not completed.Which function can I use for uncompleted images.Thank you so much.</p>Yuki Zuehttp://www.mathworks.com/matlabcentral/profile/authors/7605430-yuki-zuetag:www.mathworks.com,2005:Question/3213702017-01-21T14:35:57Z2017-01-21T15:09:03ZCan somebody either make or point me an example of the following MATLAB optimization example:<p>1. Nonlinear Obj Fun
2. At least 2 Linear Constraints
3. At least 1 nonlinear equality constraint and at least 1 nonlinear equality constraint
4. User-supplied gradients and hessians are used</p>Kevin Russellhttp://www.mathworks.com/matlabcentral/profile/authors/6996229-kevin-russelltag:www.mathworks.com,2005:Question/3213392017-01-21T08:02:30Z2017-01-21T15:06:33ZHow can I solve set of non-linear equations.<p>I have a set of non-linear equations for solid oxide fuel cell electro-chemical model. I am trying to solve it using fsolve function which is not able to solve these.Either that gives a negative solution or imaginary solution. Please find the attached file for code. It would be great help if anybody could give some suggestions.
Thank you</p>Shamshttp://www.mathworks.com/matlabcentral/profile/authors/9565678-shamstag:www.mathworks.com,2005:Question/3213712017-01-21T14:43:58Z2017-01-21T14:43:58ZWhy my AC voltage source not provides a sine curve?<p>Hello,
I run simulink to see the voltage graph of AC source but how it shows like this? Do I set some parameters wrong? AC voltage peak value is set at 100v others parameters are left as default.</p><img src = "/matlabcentral/answers/uploaded_files/68023/AC%20simulate.JPG"><img src = "/matlabcentral/answers/uploaded_files/68024/AC%20simulate2.JPG">Patchayatorn Putmeehttp://www.mathworks.com/matlabcentral/profile/authors/9482074-patchayatorn-putmeetag:www.mathworks.com,2005:Question/3212612017-01-20T16:03:52Z2017-01-21T14:29:16ZPlotting from mat file<p>My problem is plotting from filename.mat which has four columns:years,months,days and value for that date. Howdo i separate certain data from such a file,if i want for example plot only the values for 1st and 2nd mont of every year? mat file is included</p>Emil Eterovichttp://www.mathworks.com/matlabcentral/profile/authors/9561878-emil-eterovic