https://ch.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2017-06-27T15:37:55Ztag:ch.mathworks.com,2005:Question/3464632017-06-27T15:37:55Z2017-06-27T15:37:55ZFor Loop Indices Manipulation<p>Hi all. I have a function file which has a for loop which, depending on the conditions, returns certain equations that should end up creating a vector of differential equations, of number x that is determined by user input, that would be solved with 'ode45' in the main m-file. The issue is that the loop must start at 3 in order to have real positive integers.</p><pre class="language-matlab">function [ DeltaO2Concentration ] = O2Solver_beta(t,O2Conc,c,O2Leak_term,nodes_num,slt_nodes2,last_node)
%UNTITLED Test function used to solve 'first attempt' code.
% System of ODE diffusion equations that will be solved using 'ode45'
% function. Inputs are constant composed of universal and calculated
% constants, time (independent variable), O2Conc (dependent variable),
% O2Leak which is a separate term or something.
</pre><pre class="language-matlab">%VECTOR LENGTH WILL NEED TO VARY ACCORDING TO USER INPUT%
</pre><pre class="language-matlab">% DeltaO2Concentration = [0;
% c*t*(O2Conc(1)-O2Conc(2)+O2Conc(3)-O2Conc(2));
% c*t*(O2Conc(2)-O2Conc(3)+O2Conc(4)-O2Conc(3));
% c*t*(O2Conc(3)-O2Conc(4)+O2Conc(5)-O2Conc(4))%+O2Leak;
% c*t*(O2Conc(4)-O2Conc(5)+O2Conc(6)-O2Conc(5));
% c*t*(O2Conc(5)-O2Conc(6)+O2Conc(7)-O2Conc(6));
% c*t*(O2Conc(6)-O2Conc(7)+O2Conc(8)-O2Conc(7))+O2Leak;
% c*t*(O2Conc(7)-O2Conc(8)+O2Conc(9)-O2Conc(8))+O2Leak;
% c*t*(O2Conc(8)-O2Conc(9)+O2Conc(10)-O2Conc(9))+O2Leak;
% c*t*(O2Conc(9)-O2Conc(10)+O2Conc(11)-O2Conc(10));
% c*t*(O2Conc(10)-O2Conc(11)+O2Conc(12)-O2Conc(11));
% c*t*(O2Conc(11)-O2Conc(12)+O2Conc(13)-O2Conc(12));
% c*t*(O2Conc(12)-O2Conc(13)+O2Conc(14)-O2Conc(13))%+O2Leak;
% c*t*(O2Conc(13)-O2Conc(14)+O2Conc(15)-O2Conc(14));
% c*t*(O2Conc(14)-O2Conc(15)+O2Conc(16)-O2Conc(15))%+O2Leak;
% c*t*(O2Conc(15)-O2Conc(16)+O2Conc(17)-O2Conc(16));
% c*t*(O2Conc(16)-O2Conc(17)+O2Conc(18)-O2Conc(17));
% c*t*(O2Conc(17)-O2Conc(18)+O2Conc(19)-O2Conc(18))%+O2Leak;
% c*t*(O2Conc(18)-O2Conc(19)+O2Conc(20)-O2Conc(19));
% 0];
</pre><pre class="language-matlab">terminate= nodes_num;
DeltaO2Concentration= zeros(1,terminate);
cnt= 1;
for i= 3:length(DeltaO2Concentration)
if i==3 && ismember(i,slt_nodes2)
DeltaO2Concentration(cnt) = c*t*(O2Conc(i-2)-O2Conc(i-1))+O2Leak_term; %first node, leakage
elseif i==3
DeltaO2Concentration(cnt) = c*t*(O2Conc(i-2)-O2Conc(i-1)); %first node, NO leakage
elseif i==last_node && ismember(i,slt_nodes2)
DeltaO2Concentration(cnt) = c*t*(O2Conc(i)-O2Conc(i-1))+O2Leak_term; %last node, leakage
elseif i==last_node
DeltaO2Concentration(cnt) = c*t*(O2Conc(i)-O2Conc(i-1)); %last node, NO leakage
elseif ismember(i,slt_nodes2)
DeltaO2Concentration(cnt) = c*t*(O2Conc(i-2)-O2Conc(i-1)+O2Conc(i)-O2Conc(i-1))+O2Leak_term; %other nodes, leakage
else
DeltaO2Concentration(cnt) = c*t*(O2Conc(i-2)-O2Conc(i-1)+O2Conc(i)-O2Conc(i-1)); %other nodes, NO leakage
end
cnt= cnt+1;
end
DeltaO2Concentration= DeltaO2Concentration.'; %column vector for ODE45
</pre><p>nodes_num: number of nodes user inputs, which translates to # of ODE equations.</p><p>slt_nodes2: user input selection of specific nodes that will include the 'O2Leak_term' in equation.</p><p>The commented out stuff in the beginning is just a general template that I use to create the loop.</p><p>If I run this as it is, the 'DeltaO2Concentration' vector is the correct length, but I feel like Matlab just puts in zero vectors or something at the end because I think it should return a vector two less than the desired, but I'm not sure how to interpret it or fix it to where I get the correct output. Any help in appreciated.</p>Areeb Hussainhttps://ch.mathworks.com/matlabcentral/profile/authors/6072795-areeb-hussaintag:ch.mathworks.com,2005:Question/3461822017-06-25T11:33:53Z2017-06-27T15:34:37ZRotate around 2 axes in VRsink<p>Hello, is it possible to rotate a box around 2 axes separately by using the VR sink in Simulink? Because its just possible to have one input with the angle and one rotation axis. Thanks!</p>Stefan Zellerhttps://ch.mathworks.com/matlabcentral/profile/authors/6314094-stefan-zellertag:ch.mathworks.com,2005:Question/3464622017-06-27T15:34:15Z2017-06-27T15:36:13ZHow to do Bayesian Parameter Estimation using Optimization in Simbiology <p>Hello Matlab Community,
I have a one-compartment pharmacokinetic model with the following parameters: Ka=0.8 (1/Hour), CL=26 (Liters/Hour), Vd=947 (Liters).</p><p>I am administering is 10mg every 24-hours 14-days = 336-hours.</p><p>What I would like to do is to add in a trough plasma concentration at 14-days of 40ng/mL.</p><p>What I would like to see if Simbiology can do is to estimate the Clearance Rate (CL) alone by keeping the Ka and Vd fixed at time=336hours and concentration=40ng/mL.</p><p>I can do this manually, by adjusting the Clearance Rate parameter, but I was looking to see if this may be automated to fit the data-point or concentration at time point 336hours of 40ng/mL. Thus, time=336, concentration=40ng/mL.</p><p>Thanks for your help.</p>aeugenehttps://ch.mathworks.com/matlabcentral/profile/authors/6918013-aeugenetag:ch.mathworks.com,2005:Question/3455402017-06-20T16:40:57Z2017-06-27T15:30:06Zsim function of the neuralnetwork<p>I want to simulate the network that I got with the new data and I use results=sim(net, new data) should I normalize the new data? and to get the real value of the result of network I need to denormalize the results?
Thanks for any idea</p>Ritahttps://ch.mathworks.com/matlabcentral/profile/authors/3883383-ritatag:ch.mathworks.com,2005:Question/3464612017-06-27T15:28:20Z2017-06-27T15:28:20Zhead yaw pose duration estimation from output signal<p>I need to find the duration of head yaw movement from obtained head tracking data .</p><p>the signal plotted below has three head yaw movements . is there a way to findout the duration of signal change in the rectangles ?</p><img src = "/matlabcentral/answers/uploaded_files/81577/untitled.jpg">sarmad mhttps://ch.mathworks.com/matlabcentral/profile/authors/6551379-sarmad-mtag:ch.mathworks.com,2005:Question/3464462017-06-27T14:14:07Z2017-06-27T15:25:45ZHow to calculate the development of the amplitude of an oscillating trajectory?<p>Dear all,</p><p>The data that I'm dealing with are time series. The signals that I'm analyzing are oscillatory and I want to calculate how the amplitude of these oscillations change over time.</p><p>Ideally, I would be able to extract the amplitude for each oscillation and then plot it over time to argue about the development of the amplitude.</p><p>Any help would be highly appreciated!
Cheers,</p><p>G</p>G Mhttps://ch.mathworks.com/matlabcentral/profile/authors/7864329-g-mtag:ch.mathworks.com,2005:Question/3464602017-06-27T15:19:19Z2017-06-27T15:19:19Zimfindcircles: How to store the center coordinate of the circles when using the function in a for loop?<p>The center is saved as a double (3X2)</p><p>How can I save the coordinates at the end of each loop without overwriting it?</p>Misha Patelhttps://ch.mathworks.com/matlabcentral/profile/authors/9615512-misha-pateltag:ch.mathworks.com,2005:Question/3443852017-06-12T13:47:12Z2017-06-27T15:12:58ZLine numbers when files are being saved in cell array<p>I asked a question here on mathworks previously inquiring how to remove the line numbers from a file. In that case, I was creating smaller files from a larger one and removing the line numbers on each row. My query is today, how might I adapt that code when I am not creating new text files, rather creating a cell array.
I have the code that I used previously but the command for removing the line numbers is built into an fprintf statement. I now wish to take this same code and apply it to a cell array. The code I had been using was</p><pre class="language-matlab">str = fgetl(fid); % read the file line by line removing line breaks
[row,~,~,idx] = sscanf(str,'%f');
fprintf(f2d,'%s\n',str(idx+1:end)); %ignore the line number of each row
</pre><p>Obviously this code was more integrated into the original code. My problem arises with trying to insert the '%s\n',str(idx+1:end) code into the generation of the cell array. Is it possible to continue using textscan? As fgetl and sscanf are reading the data already making textscan superfluous. Since there is no command now to create text files, I am unsure where '%s\n',str(idx+1:end) can go. It seems that textscan is a much faster way of reading the data than fgetl as it does not need to go line by line through the data. Is there a method to combine the line number removal method with textscan or must i develop a new way for the code to remove the line number?</p><pre class="language-matlab">filePattern = fullfile(myFolder, '*.asc'); % Call all files with '.asc' from the chosen folder
Files = dir(filePattern); % list folder contents
finishCell = cell(length(Files));
for K = 1 : length(Files) % for all files files in the folder
baseFileName = Files(K).name;
FileName = fullfile(myFolder, baseFileName);
fid = fopen(FileName); % open the file from chosen folder
str = fgetl(fid); % read the file line by line removing line breaks
[row,~,~,idx] = sscanf(str,'%f'); % ignore the line number of each row
Cell = textscan( fid, '%f', 'delimiter', ';'); % scanning data from files
fclose(fid); % close file from chosen folder
data = cell2mat(Cell); % convert the cell data to matrix
N = 1024; % Number of numbers per row
Finish0 = reshape(data, N, [])'; % reshape the data into the correct format
finishCell{K} = Finish0;
end
</pre><p>Essentially, is it possible to remove line numbers from files and then save them in a cell array without making new text files?</p>Aaron Smithhttps://ch.mathworks.com/matlabcentral/profile/authors/9670029-aaron-smithtag:ch.mathworks.com,2005:Question/3464572017-06-27T14:44:21Z2017-06-27T15:12:22ZDoes "clear" command clears the global variables<p>Does clear command clears all the variables in the workspace including global variables. In my code, there are lots of global variables. On running the code multiple times it seems that previous global variables are not getting cleared.</p><p>I'm using below command at the start of the Code</p><pre class="language-matlab">clear;
</pre>Atinesh Singhhttps://ch.mathworks.com/matlabcentral/profile/authors/8382894-atinesh-singhtag:ch.mathworks.com,2005:Question/3462612017-06-26T11:29:00Z2017-06-27T15:11:11ZWhy can't MEX find a supported compiler in MATLAB R2017a in macOS Sierra<p>I'm using the latest macOS (Sierra 10.12.5) and mex can not find the compiler, or SDK even if the latest Xcode (8.3.3) and Intel Paralell Studio are installed.</p>Peter Kerekeshttps://ch.mathworks.com/matlabcentral/profile/authors/10071291-peter-kerekestag:ch.mathworks.com,2005:Question/3454642017-06-20T09:04:11Z2017-06-27T15:08:26Zrecurrence relation for any given 'n'.<p>How to compute A_j^(2n) for any 'n' using A_j^(2).</p><p>Here, n=2,3,4,...; and j=1:n-1.</p><img src = "/matlabcentral/answers/uploaded_files/81041/Eq.png"><p>Any kind of help is highly appreciated.</p><p>Thank you.</p>Venkatahttps://ch.mathworks.com/matlabcentral/profile/authors/2389187-venkatatag:ch.mathworks.com,2005:Question/3461172017-06-24T14:38:00Z2017-06-27T15:02:45ZStructure from shaperead: Logical indexing gives a 'one row shift'<p>Dear all,
I am facing a issue regarding logical indexing of elements in a structure loaded from a 'shaperead' call.</p><p>Indeed, what I did:
(1) I load a shape file of points (let's say 'myPoints'), with one field of interest, which is -let's say- 'ID'.
(2) Once loaded, I add a new field 'Cluster' with a for loop:</p><pre class="language-matlab">for i=1:length(names)
try
myPoints([myPoints.ID]==str2double(names(i,:))).Cluster=T(i);
catch
disp(['No point for point n°',names(i,:)]) % This can happen
end
end
</pre><p>note that the array 'names' is the same length as 'T'. Each line in 'names' refers to the field 'ID' in the structure, and I join the corresponding 'T' value to the field 'Cluster'</p><p>(3) I prepare a List of clusters and desired colors for mapping:</p><pre class="language-matlab">ListOfClusters=unique(T);
ListOfColors=distinguishable_colors(length(ListOfClusters));
</pre><p>Until here, everything goes great: When I look at the structure 'myPoints', the right value of 'Cluster' is attached to the right row/observation.</p><p>Then comes the mapping and I thought building a loop, which plots all the points of a certain cluster with a specific predefined color ('ListOfColors'), then map the next cluster, etc.</p><pre class="language-matlab">figure
hold on
for i=1:length(ListOfClusters)
StyleOfPoints=makesymbolspec('Point',{'Default','Marker','o','MarkerFaceColor',ListOfColors(i,:),'MarkerEdgeColor',ListOfColors(i,:)});
MappedPoints(i)=mapshow(myPoints([myPoints(:).Cluster]==ListOfClusters(i)),'SymbolSpec',StyleOfPoints);
MappedPoints(i).DisplayName=num2str(ListOfClusters(i),'Cluster %d');
end
</pre><p>Here is the problem: The logical indexing:</p><pre class="language-matlab">[myPoints(:).Cluster]==ListOfClusters(i)
</pre><p>returns the wrong index for all loop iteration, and it is always shifted to the previous row(s) from the right one(s). For instance, Cluster value of 7 has only one observation at row 35, but the previous logical indexing returns a 1 in column 34 (This is how I first tracked the problem). This seems to be the same problem for all values of Cluster and I can not realise what I did wrong...</p><p>Does anyone have an idea? Thanks!</p><p>PS: I can send sample data if needed.</p>Water_RChttps://ch.mathworks.com/matlabcentral/profile/authors/6436350-water_rctag:ch.mathworks.com,2005:Question/3464402017-06-27T13:37:45Z2017-06-27T14:59:21ZIndex are not used completely<p>Hello, me again.
I have a set of data. I have a to calculate small current. So I need max and min. But since is a noisy signal I can't use peak2peak. So what I did. In a range predetermine. I take the max.. find the index. later from that index I calculate a new range, to make the mean around that number. For each cell I have 5 traces. My problem is the following: I calculate the max for each trace, the index, then when I want to calculate the mean, the range it choose to find the new numbers is not taken in consideration. Only uses the first index I calculate.</p><pre class="language-matlab">[valmax, idxmax]= max(input.current(:,1002:1032),[],2);
indexFromZero (:,ii,jj)= 1002+idxmax-1;
MaximumMean(:,ii,jj)= mean(input.current(:,indexFromZero-1:indexFromZero+1),2);
indexMinimumRange(:,ii,jj)=indexFromZero (:,ii) +40;
[valmin, idxmin]= min(input.current(:,indexMinimumRange-1:indexMinimumRange+1),[],2);
MinmumMean(:,ii,jj)=mean(input.current(:,indexMinimumRange-1:indexMinimumRange+1),2);
Ih(:,ii)=MaximumMean(:,ii)-MinmumMean(:,ii);
</pre><p>So indexFromZero is a matrix with the index for all the traces.But it always calculates in the range of 1017, the first number.</p><pre class="language-matlab">1017
1016
1026
1024
1021
</pre><p>[ii and jj are the cell number and the sheet from excel where the information of the cell is]</p>Milagros ARIETTIhttps://ch.mathworks.com/matlabcentral/profile/authors/7139067-milagros-ariettitag:ch.mathworks.com,2005:Question/3464522017-06-27T14:30:04Z2017-06-27T14:58:29ZHow to tell what subfunction ran last in a GUI? For debugging.<p>I am testing a complex GUI written by someone else. If I push certain buttons in sequence a bug appears: instead of plotting a recently-loaded image, an old image is plotted. It's hard to tell what part of the program causes the bug: each button calls several functions, and there are many imshow calls. To pinpoint which imshow command retrieves the outdated image, is there a way to tell <b>what function or line of code last ran</b>, perhaps from the command line?</p><p>[Since I don't know where in the code the problem occurs, breakpoints are cumbersome because I'd have to put them into all the functions, plus I find it hard to 'step out' of debugging which I believe is a known issue with GUIs in R2015b.]</p>KAEhttps://ch.mathworks.com/matlabcentral/profile/authors/9495793-kaetag:ch.mathworks.com,2005:Question/3462902017-06-26T14:16:31Z2017-06-27T14:56:57ZInitial values in nlinfit or fitnlm <p>I am trying to run a non-linear multiple variable model in Matlab. The model has about 20 coefficients. I have been using 1s as my initial values in developing the model, and my model has an acceptable R2 value and good residual plots.
However, I am not sure if the generated coefficients are sensitive to the initial values that were assigned by me.</p><p>This begs the question of whether one can check if the generated coefficient values are highly sensitive to the assigned initial values? Or one should do it manually, ie test the model with different set of initial values and compare the RMSE of the model?</p>wesleynotwisehttps://ch.mathworks.com/matlabcentral/profile/authors/10338091-wesleynotwisetag:ch.mathworks.com,2005:Question/3464532017-06-27T14:33:36Z2017-06-27T14:54:11ZIteration for loop cell array storage<p>I am doing a for loop that outputs a matrix "R" every iteration.
I wanted to make a cell array to store each matrix however it only stores the final output i.e. overwrites the cell every iteration - any help?</p><pre class="language-matlab">ct=0;
for diamrod1 = 10e-9:5e-9:20e-9;
[r,t,R,T]=fv_trans_refl_2D_slabs(F, materials, d, pol);
ct=ct+1;
Rcollected{ct,1}=R;
end
</pre><p>after I run it the Rcollected cell only has a saved matrix at ct=3.</p>Serena Campbellhttps://ch.mathworks.com/matlabcentral/profile/authors/6449610-serena-campbelltag:ch.mathworks.com,2005:Question/3464472017-06-27T14:14:19Z2017-06-27T14:54:08ZHow to get only foldername with uigetdir<p>Hello, I want to select a folder (would be subfolder2 in my example) and use its name as a string.
The problem is that not only the foldername but the whole location is the output of uigetdir().</p><pre> name = uigetdir('./subfolder1/');</pre><p>Is there a simple function to just get the name of the selected folder?</p><p>Cheers, J</p>Jonas Khttps://ch.mathworks.com/matlabcentral/profile/authors/7693918-jonas-ktag:ch.mathworks.com,2005:Question/3464592017-06-27T14:53:44Z2017-06-27T14:53:44ZCreating a semicircle plot of angular (azimuth) data in MATLAB<p>Hi,</p><p>I would like to use MATLAB to create a figure whereby multiple data points are plotted such that their orientation (azimuth <180 degrees) is on the circumference and their width is on the radius. I have created a sketch of my intention.</p><p>Example data:</p><p>Orientation (deg)/Thickness (cm)</p><p>098/50</p><p>150/87</p><p>023/64</p><p>Is this possible in MATLAB?</p><p>Many thanks,</p><p>Alex</p><img src = "/matlabcentral/answers/uploaded_files/81574/text4583.png">Alexander Peacehttps://ch.mathworks.com/matlabcentral/profile/authors/10529031-alexander-peacetag:ch.mathworks.com,2005:Question/3464582017-06-27T14:46:32Z2017-06-27T14:50:01ZError using sqpInterface Objective function is undefined at initial point. <p>while using nmpc example of the inverted pendulum.I am getting this error. I just change model to double pendulum model in pendulumCT.m file. what should I do?
Error using sqpInterface
Objective function is undefined at initial point. Fmincon cannot continue.</p><p>Error in fmincon (line 808)
[X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] = sqpInterface(funfcn,X,full(A),full(B),full(Aeq),full(Beq), ...</p><p>Error in nmpc (line 52)
uopt = fmincon(COSTFUN,uopt,[],[],[],[],LB,UB,CONSFUN,options);</p>Rajan Pandyahttps://ch.mathworks.com/matlabcentral/profile/authors/10512572-rajan-pandyatag:ch.mathworks.com,2005:Question/3431442017-06-03T08:51:56Z2017-06-27T14:48:39ZWhy does AlexNet have non-scalar values for NumChannels and NumFilters in some convolutional layers?<p>Take the layers 'conv1' and 'conv2' for example. 'conv1' has 3 channels and 96 filters; that's fine. It should follow that 'conv2' has 96 channels, but instead what I find is the following:</p><ul><li>conv2.NumChannels = [48 48]</li><li>conv2.Weights has the following form: [5×5×48×256 single]</li></ul><p>The total of the elements in conv2.NumChannels is the required 96, but why is this split into 2 48s?</p><p>The conv2.Weights property suggests that there are only 48 channels, not the required 96. Are half the filters in 'conv1' redundant as a result?</p><p>It is impossible to construct a Convolution2DLayer with a 2-element NumChannels, so how did this happen?</p><p>From here the confusion continues because conv2.NumFilters = [128 128]. The total is 256, which is the correct number of filters, and is consistent with the conv.2.Weights property written above. But again, why is this split across 2 elements? And how did this happen given that it is impossible to construct a Convolution2DLayer with a non-scaler NumFilters property?</p><p>If anyone can help me to overcome this confusion, I would be very grateful</p>Philhttps://ch.mathworks.com/matlabcentral/profile/authors/9381421-philtag:ch.mathworks.com,2005:Question/3464382017-06-27T13:32:59Z2017-06-27T14:45:05Zwrong time format in table<p>I have 100000x4 table with <tt>time|voltage|voltage|voltage</tt> and i need to plot the voltages vs time.
Unfortunately the time column is in the format "d/M/y HH:mm:ss.SSSSSS" and do not start on an absolute zero.
how can i extract or change the time from '2/6/2040 00:59:59.999984' in order to make a plot of it?</p><p>R2017a</p>håkon willmannhttps://ch.mathworks.com/matlabcentral/profile/authors/10268773-hakon-willmanntag:ch.mathworks.com,2005:Question/3464562017-06-27T14:41:47Z2017-06-27T14:41:47Zhow to spread neighbors of a vertex and neighbors of its neighbors based on a criteria Dv ? <p>Hello,
I am working on a spreading method to spread neighbors of a vertex based on some criteria. I have :</p><ul><li>a 3D mesh model and a 3D mesh scene,</li><li>an array IVS of scene vertices that I have already obtained from a matching procedure.</li><li>an array mindist each element i is the minimum distance between the ith vertex on the the scene and its nearest neighbor on the model stocked in an other array matchs.(I used Knnsearch)</li><li>the liste of neighbors of each vertex neighboursOfInternal. (I used <a href = "https://www.mathworks.com/matlabcentral/answers/uploaded_files/21200/neighboringVertices.m">this code</a> to get them).</li></ul><p>so what I want to do is:</p><pre> for each vertex in IVS </pre><pre> if the distance between this vertex and its nearest neighbor (mindist(vertex)) is less than
a threshold Dv
add all its neighbors from neighboursOfInternal to IVS
repeat this procedure fro all vertices in IVS (vertices and neighbors added).</pre><p>I tried to code it like this:</p><pre class="language-matlab">function tab = Voisinage (t,idv, neighboursOfInternal,mindist)
tab = t ;
if mindist(idv) < 2 %Dv = 2 in this case
tab = [tab cell2mat(neighboursOfInternal(idv))'];
end
end
</pre><pre class="language-matlab">tab = IVS;
for i = 1 : length(tab)
disp(i);
tab = Voisinage(tab(i),neighboursOfInternal(tab(i)),mindist,0.3);
end
</pre><p>but it gives me the error :</p><pre class="language-matlab">Index exceeds matrix dimensions.
Error in Voisinage (line 5)
tab = [tab cell2mat(neighboursOfInternal(idv))'];
</pre><p>I am not very good with matlab, so ask for help. and I still working on it.</p>jihad hrourahttps://ch.mathworks.com/matlabcentral/profile/authors/6020082-jihad-hrouratag:ch.mathworks.com,2005:Question/3464552017-06-27T14:39:13Z2017-06-27T14:39:13Zhow to generate C code in matlab??<p>i have my C code(small part of my matlab code).but i dont know how to integrate it in matlab
i'm working with matlab R2016b</p>khiter hindhttps://ch.mathworks.com/matlabcentral/profile/authors/9404109-khiter-hindtag:ch.mathworks.com,2005:Question/3464342017-06-27T13:11:18Z2017-06-27T14:37:43ZMatlab Table / Dataset type optimization<p>I am searching some optimized datatypes for "observations-variables" table in Matlab, that can be fast and easily accessed by columns (through variables) and by rows (through observations).</p><p>Here is сomparison of existing Matlab datatypes:</p><ol><li><b>Matrix</b> is very fast, hovewer, it has no built-in indexing labels/enumerations for its dimensions, and you can't always remember variable name by column index.</li><li><b>Table</b> has very bad performance, especially when reading individual rows/columns in a for loop (I suppose it runs some slow convertion methods, and is designed to be more Excel-like).</li><li><b>Scalar structure</b> (structure of column arrays) datatype - fast column-wise access to variables as vectors, but slow row-wise conversion to observations.</li><li><b>Nonscalar structure</b> (array of structures) - fast row-wise access to observations as vectors, but slow column-wise conversion to variables.
I wonder if I can use some simpler and optimized version of Table data type, if I want just to combine row-number and column-variable indexing with only numerical variables -OR- any variable type.</li></ol><p>See the same question on
<a href = "https://stackoverflow.com/questions/44679592/matlab-table-dataset-type-optimization">Stack Overflow</a>.</p><p>--</p><p>Results of test script:</p><pre class="language-matlab">----
TEST1 - reading individual observations
Matrix: 0.072519 sec
Table: 18.014 sec
Array of structures: 0.49896 sec
Structure of arrays: 4.3865 sec
----
TEST2 - reading individual variables
Matrix: 0.0047834 sec
Table: 0.0017972 sec
Array of structures: 2.2715 sec
Structure of arrays: 0.0010529 sec
</pre><p>Test script:</p><pre class="language-matlab">Nobs = 1e5; % number of observations-rows
varNames={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O'};
Nvar = numel(varNames); % number of variables-colums
</pre><pre class="language-matlab">M = randn(Nobs, Nvar); % matrix
</pre><pre class="language-matlab">T = array2table(M, 'VariableNames', varNames); % table
</pre><pre class="language-matlab">NS = struct; % nonscalar structure = array of structures
for i=1:Nobs
for v=1:Nvar
NS(i).(varNames{v}) = M(i,v);
end
end
</pre><pre class="language-matlab">SS = struct; % scalar structure = structure of arrays
for v=1:Nvar
SS.(varNames{v}) = M(:,v);
end
</pre><pre class="language-matlab">%% TEST 1 - reading individual observations (row-wise)
disp('----'); disp('TEST1 - reading individual observations');
</pre><pre class="language-matlab">tic; % matrix
for i=1:Nobs
x = M(i,:); end
disp(['Matrix: ', num2str(toc()), ' sec']);
</pre><pre class="language-matlab">tic; % table
for i=1:Nobs
x = T(i,:); end
disp(['Table: ', num2str(toc), ' sec']);
</pre><pre class="language-matlab">tic;% nonscalar structure = array of structures
for i=1:Nobs
x = NS(i); end
disp(['Array of structures: ', num2str(toc()), ' sec']);
</pre><pre class="language-matlab">tic;% scalar structure = structure of arrays
for i=1:Nobs
for v=1:Nvar
x.(varNames{v}) = SS.(varNames{v})(i);
end
end
disp(['Structure of arrays: ', num2str(toc()), ' sec']);
</pre><pre class="language-matlab">%% TEST 2 - reading individual variables (column-wise)
disp('----'); disp('TEST2 - reading individual variables');
</pre><pre class="language-matlab">tic; % matrix
for v=1:Nvar
x = M(:,v); end
disp(['Matrix: ', num2str(toc()), ' sec']);
</pre><pre class="language-matlab">tic; % table
for v=1:Nvar
x = T.(varNames{v}); end
disp(['Table: ', num2str(toc()), ' sec']);
</pre><pre class="language-matlab">tic; % nonscalar structure = array of structures
for v=1:Nvar
for i=1:Nobs
x(i,1) = NS(i).(varNames{v});
end
end
disp(['Array of structures: ', num2str(toc()), ' sec']);
</pre><pre class="language-matlab">tic; % scalar structure = structure of arrays
for v=1:Nvar
x = SS.(varNames{v}); end
disp(['Structure of arrays: ', num2str(toc()), ' sec']);
</pre>Victorhttps://ch.mathworks.com/matlabcentral/profile/authors/6616112-victortag:ch.mathworks.com,2005:Question/3464542017-06-27T14:34:45Z2017-06-27T14:34:45ZHow can I define a custom exception type for Polyspace Bug Finder?<p>I am running Polyspace over some code for an embedded system. One thing that I run into is numerous warnings about uninitialized variables. However, this is due to Polyspace not knowing that a certain macro sets registers such that processing will halt, so the values would never get used. All these error handling calls are wrapped in the same macro, so is there a way I can tell Polyspace to stop at these?</p><p>There are enough of the errors that manually justifying each would be a massive effort. I'm using Polyspace R2016b</p>Trenton Holmeshttps://ch.mathworks.com/matlabcentral/profile/authors/10013185-trenton-holmestag:ch.mathworks.com,2005:Question/3462052017-06-25T19:08:55Z2017-06-27T14:28:01Zseparate excel file based one single column in matlab<img src = "/matlabcentral/answers/uploaded_files/81415/Capture.PNG"><p>I have a multiple .csv file which has time series data. I have attached a sample file. Is it possible to find every 5 minute interval in the HH:MM:SS column, cut the entire data until that time and save it as a separate file with the header row.? Likewise it has to do until the entire time series up to 5 hrs or so. Any suggestions on how to do this?</p>Daphne Mariaravihttps://ch.mathworks.com/matlabcentral/profile/authors/10442404-daphne-mariaravitag:ch.mathworks.com,2005:Question/3464512017-06-27T14:25:36Z2017-06-27T14:25:36Zhow to extract the conic constant and RoC from a measured profile of an aspheric lens. <p>I've used a confocal microscope to measure the height profile of an aspheric MLA and need to extract the conic constant and RoC from the data. I have used the "Solver" add-on for Excel to do this but would like to be able to verify my results. I do not have many if any of the toolboxes.</p><p>standard asphere equation is z(r)= c*r^2/(1+sqrt(1-(1+k)c^2r^2) where c=1/RoC, z is lens sag, r is the distance from the center of the lens and k is the conic constant.</p>Zachariah Johnsonhttps://ch.mathworks.com/matlabcentral/profile/authors/10418119-zachariah-johnsontag:ch.mathworks.com,2005:Question/3464232017-06-27T11:57:54Z2017-06-27T14:24:21ZFitting data for each row of a matrix<p>Hi there,</p><p>I have a matrix 8760x8 and I would like to fit the data of each row (8 values) with a vector like this:
[1 2 3 4 5 6 7 8]</p><p>Is it possible to do it ?</p><p>thanks</p>Nikolas Spiliopouloshttps://ch.mathworks.com/matlabcentral/profile/authors/9122757-nikolas-spiliopoulostag:ch.mathworks.com,2005:Question/3464502017-06-27T14:24:16Z2017-06-27T14:24:16ZSimulink Real-Time Windows Target: cmd ping doesn't work.<p>Hi,
I'm using Simulink Real Time Explorer to connect (via ethernet) my laptop to another one (Windows target).
I followed the instructions setting IPv4 parameters on both the computers and in fact, via WindowsCMD, my laptop was able to ping the target.
I created the boot disk and, restarting the target-PC, the kernel was downloaded. After that, I was no more able to ping the target and the <i>slrttest</i> failed.
Does anyone know why my pc stop pinging the other one after the download? Was the boot-disk wrongly created?
Thank you for your help.</p>Francesco Vinattierihttps://ch.mathworks.com/matlabcentral/profile/authors/6164034-francesco-vinattieritag:ch.mathworks.com,2005:Question/3464492017-06-27T14:23:01Z2017-06-27T14:23:01Zhow to save for loop variable output data in csv file?<p>I want to save for loop output in csv file. I want to save value of "label_index_expected" in csv file.I have tried but i am not getting how to save it.
for i = 1 : size(TV.T, 2)
[x, label_index_expected]=max(TV.T(:,i));
[x, label_index_actual]=max(TY(:,i));
if label_index_actual~=label_index_expected
MissClassificationRate_Testing=MissClassificationRate_Testing+1;
end</p>tejasveehttps://ch.mathworks.com/matlabcentral/profile/authors/5271110-tejasveetag:ch.mathworks.com,2005:Question/3460382017-06-23T18:15:57Z2017-06-27T14:21:23ZInstalled hardware adaptor for Matrox framegrabber, can't find card using matroxlist or imaqfind (found once, though)<p><b>Issue:</b></p><p>Matrox framegrabber card isn't being detected by Matlab.</p><p>I do know it can be detected by Matlab IMAQ toolbox as it has been once so far using matroxlist, but both before, and after this, I am unable to obtain a connection to the card on Matlab using matroxlist or imaqfind.</p><p><b>Error Messages Received</b></p><pre class="language-matlab">matroxlist:
</pre><pre class="language-matlab">Support Package for Matrox Hardware has not been installed. Open Add-Ons Explorer to install the Matrox Hardware Support Package.
</pre><pre class="language-matlab">imaqfind:
</pre><pre class="language-matlab">ans =
</pre><pre> []</pre><pre class="language-matlab">imaqhwinfo:
</pre><pre> struct with fields:</pre><pre> InstalledAdaptors: {'matrox'}
MATLABVersion: '9.2 (R2017a)'
ToolboxName: 'Image Acquisition Toolbox'
ToolboxVersion: '5.2 (R2017a)'</pre><p><b>What's been tested:</b></p><p>Using Matrox Intellicam, I know that the card itself is functioning as expected.</p><p>I've uninstalled and reinstalled Matlab (full reinstall including toolboxes).</p><p>I've uninstalled the hardware adaptor for Matrox, several times, and several times tried various 'tricks', including deleting the folder it was housed in, trying to force it (unsuccessfully) to install to a different directory, and finally what did work, just once, was deleting that directory and the folder after uninstalling the adaptor from Matlab. But that worked just once or twice, and the behavior started again.</p><p>I've rebooted the system after each of these steps, also.</p><p><b>Additional Info</b></p><p>Since writing this, I've reproduced getting matroxlist to work. But, have noticed that it only functions while Matlab is initially open, and then fails. I've done this twice so far, just to double check, note that the process is pretty much the same with few differences than the linked answer below. I can get Matlab to recognize the matrox card, it will just lose that recognition every time I close out of Matlab, to where I will need to perform the same steps before every time I open Matlab.</p><p>I've also tried the answer in this <a href = "https://www.mathworks.com/matlabcentral/answers/318635-how-do-i-perform-a-clean-re-installation-of-a-support-package">link</a>, as well. Behavior is the exact same as before.</p>Andrew Reinhardthttps://ch.mathworks.com/matlabcentral/profile/authors/10512385-andrew-reinhardttag:ch.mathworks.com,2005:Question/3464482017-06-27T14:21:06Z2017-06-27T14:21:06ZCan I plot a trajectory using the google earth toolbox?<p>I have a file with different data in columns including the longitude and latitude of every data point. I want to plot each of those points with all of the data at each point and I want the color of the points to change depending on the value. The code should output kml files for the data. Does anyone know how to do this?</p>Karla Haiathttps://ch.mathworks.com/matlabcentral/profile/authors/10498142-karla-haiattag:ch.mathworks.com,2005:Question/3464442017-06-27T14:11:25Z2017-06-27T14:13:53ZHow can i select 1 of the 2 outputs on the basis of conditions?<p>I am designing a controller. I have certain logical conditions on which one of the two controllers i.e. Main controller and sub controller is to be selected . I am using an "if block" with two "if action" sub blocks for selection. The output of both the controllers is a 3x1 vector. Now "if block" will select the controller based on certain conditions. But how to select one of two outputs from the controllers is my problem!!
Kindly see the attached Simulink model for more clear idea of my problem.
I have already tried merge and mux blocks but both of these cannot select one of the outputs.</p>Matihttps://ch.mathworks.com/matlabcentral/profile/authors/10528699-matitag:ch.mathworks.com,2005:Question/3464432017-06-27T14:06:14Z2017-06-27T14:13:11ZHow to create a 2D waterfall plot?<p>I would like to create a 2D spectral density waterfall plot. I imagine it would be easier to use the waterfall function somehow or even to create my own code for it by somehow using the waterfall function to create an array which displays horizontally along the y-axis, and then either shifting that row down or just plotting the new row under it. Is there a way to save the waterfall data into an array? Or a way to plot the new waterfall data with an offset on the y-axis?</p><p>the waterfall data is an array called 'sweepData' which is updated in a loop which I would like to be appended to the waterfall graph in each loop</p><p>Attached is a picture with 1 plot of the waterfall data, I just need to keep plotting the new data under it</p><p>Code:</p><p>subplot(3,1,3)</p><p>spec_dens = waterfall(sweepData);</p><p>xlabel('Frequency (MHz)')</p><p>ylabel('Sample Number')</p><p>title('Waterfall (Spectral Density Graph)')</p><p>view(0,90)</p><p>xlim([0 numSamples])</p><p>ylim([0 numCapture])</p><p>set(gca,'Ydir','reverse')</p>Veronica yephttps://ch.mathworks.com/matlabcentral/profile/authors/6202404-veronica-yeptag:ch.mathworks.com,2005:Question/3464452017-06-27T14:12:42Z2017-06-27T14:12:42ZWhy do i have NAN values in the confusion matrix only in the validation test? <p>I wanted to create neural network for binary classification for dataset with input matrix with size [9 981] and output matrix [1 981]and this is the code that i used</p><pre> rng('default');
inputs = patientInputs;
targets = patientTargets;
x = mapminmax(inputs);
t=targets;
trainFcn = 'trainbr';
% Create a Pattern Recognition Network
hiddenLayerSize =10;
net = patternnet(hiddenLayerSize,trainFcn);</pre><pre> net.divideFcn = 'dividerand'; % Divide data randomly
net.divideMode = 'sample'; % Divide up every sample
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
net.performFcn = 'mse'; </pre><pre> % Choose Plot Functions
% For a list of all plot functions type: help nnplot
net.plotFcns = {'plotperform','plottrainstate','ploterrhist', ...
'plotconfusion', 'plotroc'};</pre><pre class="language-matlab">% Train the Network
net= configure(net,x,t);
[net,tr] = train(net,x,t);
</pre><pre> y = net(x);
e = gsubtract(t,y);
performance = perform(net,t,y)
tind = vec2ind(t);
yind = vec2ind(y);
percentErrors = sum(tind ~= yind)/numel(tind);</pre><pre> % Recalculate Training, Validation and Test Performance
trainTargets = t .* tr.trainMask{1};
valTargets = t .* tr.valMask{1};
testTargets = t .* tr.testMask{1};
trainPerformance = perform(net,trainTargets,y)
valPerformance = perform(net,valTargets,y)
testPerformance = perform(net,testTargets,y)</pre><pre class="language-matlab">% View the Network
view(net)
</pre><p>At first i used the default trainFcn 'trainscg' then i tried to use 'trainbr' the accuracy improved but i got NAN values in the confusion matrix only in the validation test as you can see it here</p><img src = "/matlabcentral/answers/uploaded_files/81572/trainbr.png"><p>Can anyone help me please?</p>afefhttps://ch.mathworks.com/matlabcentral/profile/authors/9902982-afeftag:ch.mathworks.com,2005:Question/3463772017-06-27T02:54:30Z2017-06-27T14:08:52ZCircle in a matrix<p>Hello,</p><p>I want to make a matrix that has a weight of 1 inside a circle and 0 outside the circle. Along the edges in portions that are not fully inside the circle, I want it to have a partial weight based on how inside the circle it is. I have been able to successfully make a crude circle that only has 1 if it is fully in the circle and 0 otherwise, but I am not sure how to do the rest of the circle.</p><p>This is how I did it:</p><pre class="language-matlab">ref1 = (double((I-r).^2+(J-r).^2<=r^2));
</pre><p>Any hints would be extremely appreciated!</p><p>Thanks,
Melissa</p>Melissa Buechleinhttps://ch.mathworks.com/matlabcentral/profile/authors/10481913-melissa-buechleintag:ch.mathworks.com,2005:Question/1680152014-12-24T17:26:29Z2017-06-27T14:08:19Zhow to create sine wave with 50hz frequency for 1001 data points and sampling frequency 250Hz<p>how to create sine wave with 50hz frequency for 1001 data points and sampling frequency 250Hz and change its amplitude?</p>Shubhamhttps://ch.mathworks.com/matlabcentral/profile/authors/6011034-shubhamtag:ch.mathworks.com,2005:Question/3464422017-06-27T13:49:12Z2017-06-27T14:01:06Zwhen I start my GUI a ghost image superimposed on the actual image<p>When I start my gui a ghost image (looks like saved from an earlier display) appears (red one). The current image (cyan) is superimposed on the ghost.</p><p>Any idea how to get rid of this ghost image.</p><img src = "/matlabcentral/answers/uploaded_files/81570/ghost.bmp">Omer Demirkayahttps://ch.mathworks.com/matlabcentral/profile/authors/10689-omer-demirkayatag:ch.mathworks.com,2005:Question/3121982016-11-14T19:16:02Z2017-06-27T13:52:51ZHow to extract data from .nc file based on latitude, longitude, time and wind?<p>Hello,</p><p>This is my first time trying to pull data from an netCDF file using MATLAB...</p><p>here's what I did...</p><pre class="language-matlab">clear all
</pre><pre class="language-matlab">close all
</pre><pre class="language-matlab">ncid = netcdf.open('uwnd.sig995.2016.nc','NC_NOWRITE');
</pre><pre class="language-matlab">lat = netcdf.getVar(ncid,0);
</pre><pre class="language-matlab">whos lat
</pre><pre class="language-matlab">lon = netcdf.getVar(ncid,1);
</pre><pre class="language-matlab">whos lon
</pre><pre class="language-matlab">time = netcdf.getVar(ncid,2);
</pre><pre class="language-matlab">whos time
</pre><pre class="language-matlab">wind = netcdf.getVar(ncid,3); %var3 wind 4x day
</pre><pre class="language-matlab">whos wind
</pre><pre class="language-matlab">latlim = [5 -5]; %5N 5S
</pre><pre class="language-matlab">lonlim = [-50 -45]; %-50W -45W
</pre><p>I dont know how to extrat one year for exemple 2016:</p><pre class="language-matlab">timelim = [ ? ]
</pre><p>and the wind for these lat lon and time...</p><p>Any help?</p><p>Thx in advance! Regards.</p><p>Below the data:</p><pre class="language-matlab">Format:
netcdf4_classic
</pre><pre class="language-matlab">Global Attributes:
Conventions = 'COARDS'
title = '4x daily NMC reanalysis (2014)'
history = 'created 2013/12 by Hoop (netCDF2.3)'
description = 'Data is from NMC initialized reanalysis
(4x/day). These are the 0.9950 sigma level values.'
platform = 'Model'
References = 'http://www.esrl.noaa.gov/psd/data/gridded/data.ncep.reanalysis.html'
dataset_title = 'NCEP-NCAR Reanalysis 1'
</pre><pre class="language-matlab">Dimensions:
lat = 73
lon = 144
time = 1460 (UNLIMITED)
</pre><pre class="language-matlab">Variables:
</pre><pre> lat
Size: 73x1
Dimensions: lat
Datatype: single
Attributes:
units = 'degrees_north'
actual_range = [9.00e+01 -9.00e+01]
long_name = 'Latitude'
standard_name = 'latitude'
axis = 'Y'
lon
Size: 144x1
Dimensions: lon
Datatype: single
Attributes:
units = 'degrees_east'
long_name = 'Longitude'
actual_range = [0.00e+00 3.58e+02]
standard_name = 'longitude'
axis = 'X'
time
Size: 1460x1
Dimensions: time
Datatype: double
Attributes:
long_name = 'Time'
delta_t = '0000-00-00 06:00:00'
standard_name = 'time'
axis = 'T'
units = 'hours since 1800-01-01 00:00:0.0'
actual_range = [1.88e+06 1.89e+06]
uwnd
Size: 144x73x1460
Dimensions: lon,lat,time
Datatype: single
Attributes:
long_name = '4xDaily u-wind at sigma level 995'
units = 'm/s'
precision = 2
least_significant_digit = 1
GRIB_id = 33
GRIB_name = 'UGRD'
var_desc = 'u-wind'
level_desc = 'Surface'
statistic = 'Individual Obs'
parent_stat = 'Other'
missing_value = -9.97e+36
valid_range = [-1.02e+02 1.02e+02]
dataset = 'NCEP Reanalysis'
actual_range = [-3.45e+01 3.71e+01]</pre>Eliane Truccolohttps://ch.mathworks.com/matlabcentral/profile/authors/3629750-eliane-truccolotag:ch.mathworks.com,2005:Question/3463002017-06-26T15:00:56Z2017-06-27T13:50:01Zissue with distance calculation ?<pre> I'm having issue with Euclidean distance calculation, </pre><p>I have used the code bellow to calculate it:</p><pre> k=2;
D=data;
[N m]= size (data);
R_I = randsample(N,k);</pre><pre> Cnt = D(R_I,:);</pre><pre> while(true)
for l=1:N
for i=1:k
dist(:,i) = sqrt( (D - repmat(Cnt(i,:),N,1))*((Sigma)^-1) * (D -repmat(Cnt(i,:),N,1))');</pre><pre> end
end
dist=sqrt(dist);
I'm receiving an error which is:</pre><p>Subscripted assignment dimension mismatch.</p>shawinhttps://ch.mathworks.com/matlabcentral/profile/authors/5290049-shawintag:ch.mathworks.com,2005:Question/3463552017-06-26T22:13:01Z2017-06-27T13:43:59ZUnderstanding a piece of code about extracting regions within an image<p>This is a licence plate extraction code. I have posted earlier a piece of code ( <a href = "https://www.mathworks.com/matlabcentral/answers/346139-help-with-understanding-a-low-pass-filter-code">link</a> ) where horizontal and vertical histograms representing the sum of differences of gray values between neighboring pixels in an image, column-wise and row-wise were used. A low pass filter was then applied on the histograms. After that, a threshold was applied in order to eliminate regions with low histogram values.
Finaly, the algorithm finds the probabls regions and extracts the region with the highest probability of containing the license plate among those regions. I understand the whole idea but i have difficultie understanding the steps followed by the algorithm.
PS: horz and vert are respectively the horizontal and vertical histograms after being passed through a low filter.
why did he give the value of 'i' to column(j)?
What do these lines refer to : [temp column_size] = size (column);
if(mod(column_size, 2))
column(column_size+1) = cols?</p><pre class="language-matlab">if true
% %% Find Probable candidates for Number Plate
j = 1;
for i = 2:cols-2
if(horz(i) ~= 0 && horz(i-1) == 0 && horz(i+1) == 0)
column(j) = i;
column(j+1) = i;
j = j + 2;
elseif((horz(i) ~= 0 && horz(i-1) == 0) || (horz(i) ~= 0 && horz(i+1) == 0))
column(j) = i;
j = j+1;
end
end
j = 1;
for i = 2:rows-2
if(vert(i) ~= 0 && vert(i-1) == 0 && vert(i+1) == 0)
row(j) = i;
row(j+1) = i;
j = j + 2;
elseif((vert(i) ~= 0 && vert(i-1) == 0) || (vert(i) ~= 0 && vert(i+1) == 0))
row(j) = i;
j = j+1;
end
end
[temp column_size] = size (column);
if(mod(column_size, 2))
column(column_size+1) = cols;
end
[temp row_size] = size (row);
if(mod(row_size, 2))
row(row_size+1) = rows;
end
%% Region of Interest Extraction
%Check each probable candidate
for i = 1:2:row_size
for j = 1:2:column_size
% If it is not the most probable region remove it from image
if(~((max_horz >= column(j) && max_horz <= column(j+1)) && (max_vert >=row(i) && max_vert <= row(i+1))))
%This loop is only for displaying proper output to User
for m = row(i):row(i+1)
for n = column(j):column(j+1)
I(m, n) = 0;
end
end
end
end
end
</pre><pre class="language-matlab">end
</pre>abichhttps://ch.mathworks.com/matlabcentral/profile/authors/10278755-abichtag:ch.mathworks.com,2005:Question/3463862017-06-27T05:59:46Z2017-06-27T13:38:19ZThreshold value is not working properly in my code<p>setting dynamic threshold value in matlab, what i am finding, below threshold value also variables get dynamic memorry allocation. So why this is happending no idea . And as well as could we check the things using matlab coder also?</p>soumyajit pandehttps://ch.mathworks.com/matlabcentral/profile/authors/10357862-soumyajit-pandetag:ch.mathworks.com,2005:Question/3464412017-06-27T13:38:18Z2017-06-27T13:38:18ZHow to simulate network performance characteristics in Matlab?<p>I'm working on a control application that involves sending image features to a remote
computing resource. The Simulink model and the remote resource -- currently a server
located in-house -- exchange messages using UDPSend and UDPReceive blocks. I want to
simulate a scenario where the algorithm that processes the input features is located
in the cloud and connected via the Internet. In such scenario, the message exchanges will
be subject to conditions such as varying delays, bandwidth availability, packet loss, and
congestion -- unlike the present working model where the message exchanges are almost
instantaneous and no loss.</p><p>Can someone provide me with advice on how to realize the above goal? Which of the
toolboxes offer the capabilities to achieve the same?</p><p>Thanks.</p>Arun Adiththanhttps://ch.mathworks.com/matlabcentral/profile/authors/9582085-arun-adiththantag:ch.mathworks.com,2005:Question/3464392017-06-27T13:34:58Z2017-06-27T13:41:54ZSave Simulink subsystem output as constant <p>I have a simulink system with multiple subsystems. In one subsystem, I want the output to be a constant singlular value not updating with time. Simulink naturally has the value updating with time but I want to save the first value as a constant to use elsewhere in the simulation. Basically like a specified constants block. Any ideas on how to stop the output from updating with time?</p>Andrew Poissanthttps://ch.mathworks.com/matlabcentral/profile/authors/4445510-andrew-poissanttag:ch.mathworks.com,2005:Question/3464322017-06-27T12:51:13Z2017-06-27T13:28:27ZEvaluating Fourier transform at a value<p>If I write</p><pre class="language-matlab">F = fourier(exp(-x^2))
</pre><p>then Matlab returns (as expected),</p><pre class="language-matlab">F =
</pre><pre class="language-matlab">pi^(1/2)*exp(-w^2/4)
</pre><p>I would like to evaluate this at a point, say</p><pre class="language-matlab">F(0)
</pre><p>However, if I write this, Matlab returns an error. What is the correct syntax?</p>Marco Gorellihttps://ch.mathworks.com/matlabcentral/profile/authors/9025146-marco-gorellitag:ch.mathworks.com,2005:Question/3464362017-06-27T13:24:07Z2017-06-27T13:28:05ZHow to use latex interpreter for xticklabels?<p>How to use latex interpreter for xticklabels or yticklabels?</p>Mr M.https://ch.mathworks.com/matlabcentral/profile/authors/4980938-mr-mtag:ch.mathworks.com,2005:Question/3464372017-06-27T13:27:12Z2017-06-27T13:42:31ZNeural network fitting function<p>Hi!
It could be a trivial question. But being new to Matlab I facing a huge problem.
I want to fit my one dimension data (X - Y) (39 points) by using a NN fit and then want to use the fitted function to get the value of Y at different value of X.
Now using nn toolbox (nftool) I tried to fit the function. RMS error is negligible small. I generated the matlab function (genfunction). But now I dont know how to use the function to get the value of Y at X= 1.25.
Could any one please suggest me to solve the problem.
Thanks in advance
Tanmoy Roy</p><p>function [Y,Xf,Af] = myNeuralNetworkFunction(X,~,~)</p><p>%MYNEURALNETWORKFUNCTION neural network simulation function.</p><p>%
% Generated by Neural Network Toolbox function genFunction, 27-Jun-2017 18:27:50.
%</p><p>% [Y] = myNeuralNetworkFunction(X,~,~) takes these arguments:
%</p><p>% X = 1xTS cell, 1 inputs over TS timesteps</p><p>% Each X{1,ts} = 39xQ matrix, input #1 at timestep ts.
%</p><p>% and returns:</p><p>% Y = 1xTS cell of 1 outputs over TS timesteps.</p><p>% Each Y{1,ts} = 39xQ matrix, output #1 at timestep ts.
%</p><p>% where Q is number of samples (or series) and TS is the number of timesteps.</p>Tanmoy Royhttps://ch.mathworks.com/matlabcentral/profile/authors/10325270-tanmoy-roytag:ch.mathworks.com,2005:Question/3464352017-06-27T13:21:29Z2017-06-27T13:25:37ZHello Guys, please some one help me in matlab code?<p>Hello Guys, please some one help me that I have cervical cancer cell with nucleus and cytoplasm. So I need to segment both nucleus and cytoplasm with different colors without changing the natural color of the image....like RGB so that I need help.
Eg: I use the following code to separate the HSV
I=imread('image2128.jpg');
Ihsv=rgb2hsv(I);
H=Ihsv(:,:,1);
S=Ihsv(:,:,2);
V=Ihsv(:,:,3);
Then I will get the plot of all separate H,S and V image. But in medical image processing I don't want to convert rgb image to grayscale image as it make us loose some information. so I need all you to help me how to apply convolution in every channel and re-combine the three hvs channel to get the final segmented color image.
Regards
Sakata Abera</p>Sakata Mengeshahttps://ch.mathworks.com/matlabcentral/profile/authors/5638884-sakata-mengeshatag:ch.mathworks.com,2005:Question/3464262017-06-27T12:22:17Z2017-06-27T13:20:48ZIf I start with a matrix of zeros, how can I easily create a circle of ones in that matrix?<p>I have a matrix of zeros, but would like a circle of ones in that matrix.
Preferably I would like the circle to fill half the area of the matrix, but this is not a necessity.</p><p>Thanks in advance!</p>Daniel Grayhttps://ch.mathworks.com/matlabcentral/profile/authors/10476527-daniel-graytag:ch.mathworks.com,2005:Question/3464112017-06-27T10:46:27Z2017-06-27T13:15:20ZHow to apply statestical algorithms using MATLAB to 'regulate' variation of a curve?<p>Hello All,</p><p>Below I am posting 2 graphs. I want to regulate the curvature of first graph using some statistical methods such as use of standard deviations, and modulate my graph to look like second one. I am not asking here for any matlab command, but for some statistical method I can implement using MATLAB.</p><p>Thnks & Regards,
Nick.</p><img src = "/matlabcentral/answers/uploaded_files/81559/MATLAB_Question_myDHI.PNG"><img src = "/matlabcentral/answers/uploaded_files/81560/MATLAB_Question_ClrDHI.PNG">Nickhttps://ch.mathworks.com/matlabcentral/profile/authors/7825183-nick