https://fr.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2017-06-27T22:31:02Ztag:fr.mathworks.com,2005:Question/3463002017-06-26T15:00:56Z2017-06-27T22:31:02Zissue 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://fr.mathworks.com/matlabcentral/profile/authors/5290049-shawintag:fr.mathworks.com,2005:Question/2166962015-05-14T14:57:44Z2017-06-27T22:30:48ZCommand Window gone crazy ( scrolls on it's own )<p>My command window has lost its mind.
It behaves normally but after I type some commands and get some output, the command window automatically scrolls up until I can't see what I just typed. The only way out is to type clc. But even that doesn't completely help.I tried typing "home" but that seems to have made things worse (I <b>think</b> it's now scrolling to a different position... or something).</p><p>How can I get back to normal?
I checked all the Matlab preferences and... nuttin!</p><p>Help?</p><p>Dan</p>Danhttps://fr.mathworks.com/matlabcentral/profile/authors/13437-dantag:fr.mathworks.com,2005:Question/3465032017-06-27T21:10:25Z2017-06-27T22:29:12ZHow to transpose a matrix<p>Matrix A as follows:</p><pre class="language-matlab">A = [1 8
1 5
1 4
2 6
2 7
2 2
2 5
7 6
7 4
7 8
9 9
9 1
9 2
9 6
9 2
];
</pre><p>I want to transpose matrix A based on the unique ID in the first column. Add 0 at the end wherever its needed in order to keep matrix dimension consistent.</p><pre class="language-matlab">out = [1 8 5 4 0 0
2 6 7 2 5 0
7 6 4 8 0 0
9 9 1 2 6 2
];
</pre>Xiehttps://fr.mathworks.com/matlabcentral/profile/authors/10440910-xietag:fr.mathworks.com,2005:Question/3464922017-06-27T19:07:19Z2017-06-27T22:28:52ZFinding the cell indices of a cell contains a specific text<p>Hi,
I am working with a large CSV file containing blood pressure data (approx 14 million datapoints). I managed to import the data successfully, creating 2 cell arrays (NUMBERS and TEXT). One contains the actual numbers that I want to use for my calculations (NUMBERS), the other (TEXT) contains the information (as a string) about the associated time-points. Since NUMBERS and TEXT run parallel, I can use the cell indices from TEXT, to get to the data in NUMBERS for further computation.</p><p>What I am trying to figure out is how to find a specific string in TEXT; e.g. what are the indices of a time point (e.g. 12:00:00)? I started to work with 'strfind' but this only gives me either 0 or 1; not the cell indices that I need. Moreover, the strings in TEXT contain 'Value, Time, Date' (eg. '103.9685,10:27:37,2016-02-03') which means that I only need the middle portion '10:27:37'of the string.</p><p>Can anyone provide me with insights/directions as to what strategy/method is best to use in this case?</p><p>Thanks!
Barry</p>B Janssenhttps://fr.mathworks.com/matlabcentral/profile/authors/2452373-b-janssentag:fr.mathworks.com,2005:Question/3460322017-06-23T17:37:30Z2017-06-27T22:25:40ZFind value in matrix that matches calculation<p>First my code does a calculation and sets it equal to ash.</p><p>I then need matlab to find all of the values that match ash in column 4 and average them. (The first three numbers should be the same but after the decimal will differ),</p><p>But there is a number next to it in column 3 that I need it to store (for each value found in column 4) and average of these numbers as well.</p><p>How would I do that.</p><p>Here is what I have so far. I look at column 4, starting with the second value to the end I have it compare to the ash value. But it doesn't seem to work.</p><p>eledata = (data(2:end,4))==ash;</p>hi heyhttps://fr.mathworks.com/matlabcentral/profile/authors/10452425-hi-heytag:fr.mathworks.com,2005:Question/3461332017-06-24T20:06:36Z2017-06-27T22:22:24Zhow can i setup open cv in matlab 2014 a when getting these errors?<p>I'm using Windows 7 (64bit) with Matlab R2014a and I'm trying to use OpenCV 3.1.0 functions in Matlab.</p><p>I first did mex -setup, then I chose the compiler 'Microsoft Windows SDK 7.1 (C++)' (detected by Matlab after patching it), added mexopencv folder and subfolders to path and finally run mexopencv.make.</p><p>the following error appears:</p><pre class="language-matlab">Error using mexopencv.make>pkg_config (line 316)
OpenCV library path not found: C:\opencv\build\x64\vc10\lib
</pre><pre class="language-matlab">Error in mexopencv.make>mex_options (line 256)
[cv_cflags, cv_libs] = pkg_config(opts);
</pre><pre class="language-matlab">Error in mexopencv.make (line 81)
mex_flags = mex_options(opts);
</pre><p>I also tried with OpenCV 2.9.0 but the error remains same</p><p>My OpenCV folder contain following folders in the C:\opencv\build\x64</p><pre> vc12
vc14</pre><p>Please help me</p><p>thanks</p>ANKIT DADHICHhttps://fr.mathworks.com/matlabcentral/profile/authors/10400427-ankit-dadhichtag:fr.mathworks.com,2005:Question/3464732017-06-27T16:34:15Z2017-06-27T22:13:32ZRadiobutton help, compiling error<p>Hi all, I've run into a strange problem while trying to incorporate radio buttons into my GUI. I'm programming it completely, and I've run into the following error:</p><p><i>Error using <b>uiradiobutton</b> (line 11)</i></p><p><i>Functionality not supported with figures created with the figure function. For more information, see Graphics Support in App Designer.</i></p><p>So I'm not using App Designer at all, and I've almost copied the example line by line.</p><p>Here's my code:</p><pre class="language-matlab">scrsz = get(0,'ScreenSize');
screensize_factor = 0.5;
figsize = [(scrsz(3)*(1-screensize_factor))./2 (scrsz(4)*(1-screensize_factor))./2 ...
scrsz(3)*screensize_factor scrsz(4)*screensize_factor];
handles.myfig = figure('units','pixels','Position',figsize,...
'menubar','none','name','main_figure',...
'numbertitle','off','resize','on',...
'Visible','off','color',[1,1,1],'Tag','myfig');
handles.mypanel = uipanel(handles.myfig,'BorderType','none','BackgroundColor',clr,'Visible','off','Position',panpos,'Tag','mypanel');
mybg = uibuttongroup(handles.mypanel, 'Title', 'bg', 'position',[0 0.3 .47 0.25]);
mybuttonone = uiradiobutton(mybg,... %<<<<<<<< This is where the code fails to compile and the error appears in the command window <<<<<<<
'Text', 'One',...
'Position', [0.1 0.6 0.4 0.2]);
mybuttontwo = uiradiobutton(mybg,...
'Text', 'Two',...
'Position', [0.1 0.4 0.4 0.2]);
mybuttonthree = uiradiobutton(mybg,...
'Text', 'Three',...
'Position', [0.1 0.2 0.4 0.2]);
</pre><p>Is there just something that I'm missing? I followed the instructions here: <a href = "https://www.mathworks.com/help/matlab/ref/uibuttongroup.html">https://www.mathworks.com/help/matlab/ref/uibuttongroup.html</a>
and I just don't know what to do here.</p>Mandeguzhttps://fr.mathworks.com/matlabcentral/profile/authors/10385623-mandeguztag:fr.mathworks.com,2005:Question/3465092017-06-27T21:51:01Z2017-06-27T22:11:48Z{} and () brackets - creating array in for loop<p>Hi everyone. I read the following answer on stack exchange:</p><p>https://stackoverflow.com/questions/9055015/difference-between-accessing-cell-elements-using-and-curly-braces-vs-par</p><p>Why this code work:</p><pre class="language-matlab">t=[0:0.01:5];
a=[0:1:5];
n=length(a);
for i=1:n
plot(t,t.^a(i));
M(i)=getframe(gcf);
end
</pre><p>while this does not work:</p><pre class="language-matlab">t=[0:0.1:10];
for i=1:5
plot(t,t.^i)
f=getframe(gcf);
immagine(i)=frame2im(f);
end
</pre><p>but immagine{i}=frame2im(f); works?</p><p>I don't understand how use () and {}. In M(i) the () brackets work, while in immagine(i) don't work.</p><p>Thank you very much for your help.</p>Gennaro Arguzzihttps://fr.mathworks.com/matlabcentral/profile/authors/5269044-gennaro-arguzzitag:fr.mathworks.com,2005:Question/3465012017-06-27T20:04:55Z2017-06-27T22:05:27ZUsing a loop to add to dataset without overwriting previous calculations<p>I have a code which makes a number of calculations based on a set of experimental data. The output is currently several matrices, each for one of 5 experimental conditions, and each of which provides the data for that condition (e.g. Subject Number, VariableX, VariableY, etc).</p><p><b>General issue:</b> I need to calculate these matrices for 50 subjects to create one big data set for each condition. To do this, I made a loop of the code. My problem is that the code then just now returns the data for the last subject. E.g., it writes over the data for the previous subject on each loop. I would like to fix it so that on each loop it just adds the data for that subject to the matrix of data for that condition. I don't know how to do this.</p><p>The further problem is that there are not an equal number of data points for each subject, so concatenating the matrix on each loop is probably not possible? I think I need to use accumarray or something similar? Any thoughts or ideas would be very helpful - I am not too experienced at this.</p><p>The code is long and messy, but here is a shortened version with the crucial elements:</p><pre class="language-matlab">subjStart = 1;
subjFinish = 54;
nSubj = 54;
</pre><pre class="language-matlab">for gg = subjStart:subjFinish
</pre><pre class="language-matlab">%%%%%%%%%%%%%%%%%%%%%%%%%%%%
</pre><pre class="language-matlab">%Code to calculate all the variables used in the following data tables
</pre><pre class="language-matlab">%%%%%%%%%%%%%%%%%%%%%%%%%%%%
</pre><pre class="language-matlab">%Create Data Tables
</pre><pre class="language-matlab">yy = (ones([1,length(SIcon1)])) .* gg; %vector of subject number
yy = yy'; %make column
dd = (ones([1,length(SIcon1)])) .* dist; %vector of distance criterion
dd = dd'; %make column
cc = (ones([1,length(SIcon1)])); %condition
cc = cc'; %make column
SubjDataCon1 = [yy dd cc SIcon1 SurveyNumCon1]; %data for condition 1 for each survey
</pre><pre class="language-matlab">yy = (ones([1,length(SIcon2)])) .* gg; %vector of subject number
yy = yy'; %make column
dd = (ones([1,length(SIcon2)])) .* dist; %vector of distance criterion
dd = dd'; %make column
cc = (ones([1,length(SIcon2)])) .*2; %condition
cc = cc'; %make column
SubjDataCon2 = [yy dd cc SIcon2 SurveyNumCon2]; %data for condition 2 for each survey
</pre><pre class="language-matlab">yy = (ones([1,length(SIcon3)])) .* gg; %vector of subject number
yy = yy'; %make column
dd = (ones([1,length(SIcon3)])) .* dist; %vector of distance criterion
dd = dd'; %make column
cc = (ones([1,length(SIcon3)])) .*3; %condition
cc = cc'; %make column
SubjDataCon3 = [yy dd cc SIcon3 SurveyNumCon3]; %data for condition 3 for each survey
</pre><pre class="language-matlab">yy = (ones([1,length(SIcon4)])) .* gg; %vector of subject number
yy = yy'; %make column
dd = (ones([1,length(SIcon4)])) .* dist; %vector of distance criterion
dd = dd'; %make column
cc = (ones([1,length(SIcon4)])) .*4; %condition
cc = cc'; %make column
SubjDataCon4 = [yy dd cc SIcon4 SurveyNumCon4]; %data for condition 4 for each survey
</pre><pre class="language-matlab">yy = (ones([1,length(SIcon56)])) .* gg; %vector of subject number
yy = yy'; %make column
dd = (ones([1,length(SIcon56)])) .* dist; %vector of distance criterion
dd = dd'; %make column
cc = (ones([1,length(SIcon56)])) .*56; %condition
cc = cc'; %make column
SubjDataCon56 = [yy dd cc SIcon56 SurveyNumCon56]; %data for condition 56 for each survey
</pre><pre class="language-matlab">clear yy;
clear dd;
clear cc;
clear SIcon1;
clear SIcon2;
clear SIcon3;
clear SIcon4;
clear SIcon56;
clear SurveyNumCon1;
clear SurveyNumCon2;
clear SurveyNumCon3;
clear SurveyNumCon4;
clear SurveyNumCon56;
</pre><pre class="language-matlab">end
</pre>Erik Jhttps://fr.mathworks.com/matlabcentral/profile/authors/5606579-erik-jtag:fr.mathworks.com,2005:Question/649492013-02-26T06:03:30Z2017-06-27T22:04:31ZHow can I remove the noise from EEG signal?<p>How can I remove the noise from row EEG signal?</p><p>I have used notch filter but it still does not like EEG signal?</p><p>Can some one hlep?</p>Abas Albahrihttps://fr.mathworks.com/matlabcentral/profile/authors/3600222-abas-albahritag:fr.mathworks.com,2005:Question/3465002017-06-27T20:02:31Z2017-06-27T22:01:46ZFitting my parametric function to experimental data from excel.<p>I am trying to develop a correlation for pressure drop in pipelines based on some data that I have. The data is in a an excel file that I have imported as column vectors into MATLAB. Each vector is a variable that is needed to calculate the values of the "Pi" groups that I have developed. So I have liquid velocity, gas velocity, densities, viscosities etc.</p><p>The function that I want to fit to my data looks like this:</p><p>Y = pi1^a * pi2^b * pi3^c * pi4^d * pi5^e</p><p>where a,b,c,d and e values need to be determined from the fit.</p><p>and pi1 = liq vel/gas vel ... etc.</p><p>I have experimental values for Y.</p><p>How can I go about using the curve fitting options that MATLAB offers?</p><p>Any help will be much appreciated.</p><p>Thank you :)</p>APhttps://fr.mathworks.com/matlabcentral/profile/authors/10507705-aptag:fr.mathworks.com,2005:Question/2961302016-07-18T07:39:12Z2017-06-27T21:56:15ZBlock structures and image processing<p>Hi,</p><p>I'm using a matlab code to divide the pixels of the image into blocks and return the average. at the beginning of the program I introduce the input value of the image pixels to be</p><pre class="language-matlab">XL=1;
XR=120;
YU=1;
YD=120;
</pre><p>then i introduced the new dimensions to divide the whole pixels into [10 10] size block</p><pre class="language-matlab">XC=(XR-XL+1)/10;
YC=(YD-YU+1)/10;
</pre><p>and this is how I used block pro function in my program:</p><pre class="language-matlab">PC_S_A=reshape(PC_S_A,120,120);
PC_S_A=PC_S_A';
</pre><pre> PC_S_A=PC_S_A(YU:YD,XL:XR);
fun = @(block_struct) mean2(block_struct.data);
PC_S_A = blockproc(PC_S_A,[10 10],fun);</pre><pre> pic_temp=reshape(PC_S_A,1,12*12);
pic_tank_M=[pic_tank_M;pic_temp];</pre><p>the program is working perfectly, but I want to modify the code with a loop,
I want to force the function to combine the first 10x10 pixels as one block , then I want the starting pixel for the second block to be the middle one in the first block. like in the image.</p><p>in other words I want the blocks to be shifted 5 pixels for the the starting pixel of previous block.</p><p>any suggestion how to do that???</p>Mai Khaleelhttps://fr.mathworks.com/matlabcentral/profile/authors/6162228-mai-khaleeltag:fr.mathworks.com,2005:Question/3464032017-06-27T09:20:22Z2017-06-27T21:55:23ZHow to 'walk' a mask/ROI over an image?<p>Hi,</p><p>At the moment, I am working at a script to determine the homogeneity of an image. For this, I want to 'move' an rectangular ROI (for example, 0.5cm x 0.5cm) over the image in steps of half ROI. I would like to determine for example, the mean pixel value for each ROI-selection.</p><p>So far, I can not really find a useful feature or script for this. I was wondering how this can be done the best and fastest?</p><p>Thanks in advance for the reply.</p>Kevin Semmelinkhttps://fr.mathworks.com/matlabcentral/profile/authors/2532506-kevin-semmelinktag:fr.mathworks.com,2005:Question/3465072017-06-27T21:36:13Z2017-06-27T21:53:38ZHow do I remove islands in a non-binary greyscale image?<p>I understand that bwareaopen() serves as a similar function however using the command yields a binary image when I need to retain the original intensity range.</p>Cyrus Nhttps://fr.mathworks.com/matlabcentral/profile/authors/10136570-cyrus-ntag:fr.mathworks.com,2005:Question/3465082017-06-27T21:41:11Z2017-06-27T21:42:39ZWrite Strings to Existing HDF5 file<p>Hello,
I am having difficulty writing an array of string data to an existing HDF5 file. I am able to write successfully to a new file using the HDF5 Matlab example (h5 ex_t_string.m, available at https://support.hdfgroup.org/HDF5/examples/api18-m.html), but when I modify this code to write to a new dataset within an existing HDF5 file, a random sequence of characters is generated.</p><p>My code is as follows (taken mostly from the example, but modified to write to an existing instead of new hdf5 file):</p><pre class="language-matlab">filename = 'rptestiso.h5'
</pre><pre class="language-matlab">%Assign variables for data to be written and array dimensions (taken directly from example code)
wdata = ['Parting'; 'is such'; 'sweet '; 'sorrow.'];
DIM0 = size(wdata,1);
SDIM = size(wdata,2)+1;
</pre><pre class="language-matlab">dims = DIM0;
</pre><pre class="language-matlab">%Open file using Read/Write option
file_id = H5F.open(filename,'H5F_ACC_RDWR','H5P_DEFAULT');
% Preceeding line replaces the H5F create statement in the example:
%file = H5F.create (filename, 'H5F_ACC_TRUNC', 'H5P_DEFAULT', 'H5P_DEFAULT');
</pre><pre class="language-matlab">%Create file and memory datatypes
filetype = H5T.copy ('H5T_C_S1');
H5T.set_size (filetype, SDIM-1);
memtype = H5T.copy ('H5T_C_S1');
H5T.set_size (memtype, SDIM-1);
</pre><pre class="language-matlab">% Create dataspace. Setting maximum size to [] sets the maximum
% size to be the current size.
%
space_id = H5S.create_simple (1,fliplr( dims), []);
</pre><pre class="language-matlab">% Create the dataset and write the string data to it.
%
dataset_id = H5D.create (file_id, 'DateTimeString', filetype, space_id, 'H5P_DEFAULT');
% Transpose the data to match the layout in the H5 file to match C
% generated H5 file.
H5D.write (dataset_id, memtype, 'H5S_ALL', 'H5S_ALL', 'H5P_DEFAULT', wdata);
</pre><pre class="language-matlab">%Close and release resources
H5D.close(dataset_id);
H5S.close(space_id);
H5T.close(filetype);
H5T.close(memtype);
H5F.close(file_id);
</pre><p>The output that is produced by the example in a new HDF5 file (and what I expect to be written to my existing HDF5 file) looks like this:</p><img src = "/matlabcentral/answers/uploaded_files/81613/ex_output.png"><p>The output produced by my code in the existing hdf5 file looks like this:</p><img src = "/matlabcentral/answers/uploaded_files/81614/my_output.png"><p>Wondering if anyone can tell me my this is happening, and what a solution might be.
For reference, I am using Matlab R2016a (9.0.0.341360) operating on Windows 10.</p><p>Thanks!</p>Keith Marcoehttps://fr.mathworks.com/matlabcentral/profile/authors/7359594-keith-marcoetag:fr.mathworks.com,2005:Question/757842013-05-14T21:27:37Z2017-06-27T21:38:03ZHow to isolate and display the largest connected component<p>Hello all,</p><p>I am looking to isolate the largest connected component in an image, and then display it by itself. Right now, the code I am using deletes the largest connected component and keeps everything else. I want everything else in the image to be deleted, and the largest component to remain. My code for the isolation is as follows:</p><pre> CC = bwconncomp(B);
numOfPixels = cellfun(@numel,CC.PixelIdxList);
[unused,indexOfMax] = max(numOfPixels);
B(CC.PixelIdxList{indexOfMax}) = 0;
imshow(B);</pre>N.B.https://fr.mathworks.com/matlabcentral/profile/authors/4277024-n-btag:fr.mathworks.com,2005:Question/3462612017-06-26T11:29:00Z2017-06-27T21:22:53ZWhy 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://fr.mathworks.com/matlabcentral/profile/authors/10071291-peter-kerekestag:fr.mathworks.com,2005:Question/3462902017-06-26T14:16:31Z2017-06-27T21:21:26ZInitial 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://fr.mathworks.com/matlabcentral/profile/authors/10338091-wesleynotwisetag:fr.mathworks.com,2005:Question/3463742017-06-27T01:53:43Z2017-06-27T21:19:51ZReturn values from simulannealbnd other than fval and x<p>I am optimizing an objective function which depend on profit and risk as shown below. I am using simulannealbnd function to optimize decision variable x. I want to plot profit vs risk. I am unable return the values of profit and risk for best value of decision variable x as I simulannealbnd only returns objective and x variables. I shall appreciate any help in this issue.</p><pre class="language-matlab">objective = w1* profit(x) + w2* risk(x);
</pre>Saifullah Khalidhttps://fr.mathworks.com/matlabcentral/profile/authors/9710909-saifullah-khalidtag:fr.mathworks.com,2005:Question/3465062017-06-27T21:18:57Z2017-06-27T21:18:57ZControlling an SCPI instrument in Simulink<p>Hi all,</p><p>I’m working on interfacing a dSPACE-based controller with a power supply that speaks SCPI, and I’m trying to figure out how to use their Ethernet blockset to do it, which is much like Mathworks' TCP/IP Send and TCP/IP Receive blocks. Because of how compiled Simulink models interact with their Ethernet hardware and drivers, I cannot use the Instrument Control Toolbox.</p><p>An example query would be “volt:prot?\r\n” to query the overvoltage threshold, and “volt:prot 50\r\n” to set it. The query would receive a reply something like “50\r\n”, and the command would receive no reply at all.</p><p>I can compose outbound messages easily enough with array concatenation, but I’m at a loss as to how to parse variably-sized incoming replies, or to accumulate incoming bytes until a reply has completely come across the wire. For example, a command of “<> STA?\r\n” requests a status, and gets a reply like “, 1, 2, 3, 4\r\n”. If I requested a buffer of 100 bytes, I’d have to send the command several times, and I’d get a number of replies glued together; if I requested a buffer of 1 byte, I wouldn’t know what to do with it until I got the “\r\n” pattern. I could write a stream-oriented parser for incoming messages, but that wouldn’t know, for a reply of ‘1000’, if the first ‘1’ should be multiplied against 1, 10, 100, or 1000, so that’s not a great solution.</p><p>Pure-Simulink solutions are ideal, since I need to generate code from this model, but I may be able to modify function blocks to do what's needed - the restrictions of the environment and toolchain make it dicey.</p><p>Thanks in advance!</p>chris akinshttps://fr.mathworks.com/matlabcentral/profile/authors/10468617-chris-akinstag:fr.mathworks.com,2005:Question/3465052017-06-27T21:17:44Z2017-06-27T21:17:44ZUsing DAQ command "addCounterInputChannel" to read data from multiple terminals of Encoder (NI ELVIS II - QNET DC Motor Trainer)<p><b>Hardware:</b> ELVIS II (QNET DC Motor Trainer)</p><p><b>Software Platform:</b> MATLAB/Simulink</p><p><b>Component Concerned:</b> Incremental optical encoder (ONE encoder, three terminals A, B & Z)</p><p><b>Objective:</b> To obtain direction of rotation of motor (Clockwise/Anti-clockwise) from encoder.
How to Achieve Objective: As per working principle of encoder, the direction can be measured by comparing the data from two terminals of Encoder. So, if data of Terminal A leads data of Terminal B, the motor is rotating in one direction. In case of lags in the two data, the motor is rotating in other direction. So, it means we need to measure data of the two terminals A and B so as to comment on direction.</p><p><b>Problem:</b>
MATLAB DAQ command "addCounterInputChannel(s, 'Dev2',0, 'position')" by default gives position data of Terminal A of counter (encoder) 0 of Device 2.
How I can get position data of Terminal B of the same counter (encoder) 0 of the same Device 2?</p>Jamshed Iqbalhttps://fr.mathworks.com/matlabcentral/profile/authors/1922158-jamshed-iqbaltag:fr.mathworks.com,2005:Question/3465042017-06-27T21:11:45Z2017-06-27T21:11:45ZNeed help in my thesis? (will to pay for help)<p>Hi i am masters student, doing my master thesis. my task is to calculate the penetration of a jet, which is a diesel injector spray in my case.I have captured the spray, now needs to post process it. I want to try ECN algorithm from sandia labs. I guess i am a beginner in Matlab. In the ECN example, the boundary is being detected as well the penetration is calculated. Both the codes are provided in the file below.</p><p><a href = "https://drive.google.com/file/d/0B0q_X1E7B4nkS0NSOXowZWdpN00/view?usp=sharing">Code</a></p><p>I also need to detect the boundary as well to calculate the penetration of the jet inside the cylinder.Even though by entering the right parameters, i would be able to see the penetration but i cannot able to detect the jet boundary. YOu can try running the procSchlieren.m file to start the code. Both my video as well as the example is the file shared by the link. I need to solve it on urgent basis otherwise probably have to get extension for my thesis. All the code probably need is some modifications of input and values. If anyone could help me then i am also willing to pay for it.</p><p>Thanks</p>Irfan Tahirhttps://fr.mathworks.com/matlabcentral/profile/authors/9059929-irfan-tahirtag:fr.mathworks.com,2005:Question/1571092014-10-02T13:55:00Z2017-06-27T21:03:05ZHow to get a geometric sequence?<p>Hi, I have</p><pre> tao=1000;
v=0.9;
T1=0.01;</pre><p>I want to have a geometric sequence T, where T1=T2=T3...=T1000 ( since tao=1000)</p><p>The first 100 T will be equal to T1,</p><p>The second 100 T which starts from T101 until T200= v*T1</p><p>The third 100 T ( from T201 until T300 = v*v*T1)</p><p>The fourth 100 T (from T301 till T400 = v*v*v*T1)</p><p>and so on.</p><p>How am I going to get the sequence? Thanks in advance.</p>Gracehttps://fr.mathworks.com/matlabcentral/profile/authors/5258085-gracetag:fr.mathworks.com,2005:Question/3462592017-06-26T11:01:28Z2017-06-27T20:54:41Zhow to implement an infinite series?<p>im trying to implement the function in the attached image but i get that error "</p><img src = "/matlabcentral/answers/uploaded_files/81457/New%20Bitmap%20Image%20(2).bmp"><pre class="language-matlab">Attempt to reference field of non-structure array.
</pre><p>at the step where (v) is being calculated. i dont know what it means and i dont know how to fix it</p><pre class="language-matlab">if true
clc;
close all;
N=32;
K=14;
c=0.8;
p=1;
pc=p*gamma(1+2/c);
T=399.01923099362968691492508329876;
s=T/(pc*(1+lambda);
%%
syms i j f
nlambda = 50;
lambdavals2 = linspace(0,30,nlambda);
lambdavals = 10.^(lambdavals2/10);
for L = 1 : nlambda
lambda = lambdavals(L);
for i=K:N/2
w=nchoosek(N/2,i) %first series over i
z=arrayfun(@(j)nchoosek(K+i-1,j)*(-1)^(j),0 :K+i-1, 'uniform',0)%second series over j
v=symsum((-1)^(f)*(N+j-K-i+1)^(f)*gamma((f+1)*c/2)/(factorial(f)*(p*(T/(pc*(1+lambda))))^((f+1)*c/2)),i ,0, Inf)%third series over f
pd1temp=w*z*v
end
pd1 = c * K * nchoosek(N/2,K) * pd1temp; %the whole function
end
end
</pre>fatma abdullahhttps://fr.mathworks.com/matlabcentral/profile/authors/9804561-fatma-abdullahtag:fr.mathworks.com,2005:Question/3458662017-06-22T15:28:38Z2017-06-27T20:52:29ZR2016b 2D zoom is not smooth. <p>Using R2016 the zooming in on data on 2D plot figures is very steppy. Not smooth like versions before. Like there is a "Snap to" feature. How can I get the zoom feature to act like R2015B and all earlier versions? Thanks.</p>Jonhttps://fr.mathworks.com/matlabcentral/profile/authors/371064-jontag:fr.mathworks.com,2005:Question/3464562017-06-27T14:41:47Z2017-06-27T20:39:09Zhow 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">neighboursOfInternal = neighboringVertices(vertexS);
tab = IVS;
for i = 1 : length(tab)
disp(i);
if (mindist(IVS(i)) < 2)
tab = [tab cell2mat(neighboursOfInternal(IVS(i)))'];
end
end
</pre><p>with neighboringVertices is a function that returns for each vertex in vertexS all its neighbors connected to it by edges.</p><p>the problem I have is that it spreads neignbors just for the vertices in the original array tab (IVS), but the neighbours of neignbors that i added are not taking into acount.</p><p>I hope I was clear. I need your help.</p>jihad hrourahttps://fr.mathworks.com/matlabcentral/profile/authors/6020082-jihad-hrouratag:fr.mathworks.com,2005:Question/3464392017-06-27T13:34:58Z2017-06-27T20:34:38ZSave 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://fr.mathworks.com/matlabcentral/profile/authors/4445510-andrew-poissanttag:fr.mathworks.com,2005:Question/3463032017-06-26T15:13:11Z2017-06-27T20:27:37ZHow to Create RT clock in my own GUI?<p>Hello,</p><p>I have the following code (it's upon GUI creation):</p><pre class="language-matlab">set(handles.time_caption,'String',datestr(now,13))
tmr = timer('Name','Reminder', ...
'Period',1, ... % Update the time every 1 seconds.
'StartDelay',0, ... % In seconds.
'TasksToExecute',inf, ... % number of times to update
'ExecutionMode','fixedSpacing', ...
'TimerFcn',{@updater_mg});
start(tmr); % Start the timer object.
</pre><pre class="language-matlab">function [] = updater_mg(varargin)
set(handles.time_caption , 'string' , datestr(now,13))
end
</pre><p>I receive the following error:</p><pre class="language-matlab">Error while evaluating TimerFcn for timer 'Reminder'
Undefined variable "handles" or class "handles.time_caption".
</pre><p>I understand that when I'm "inside" the updater_mg function it doesn't recognize my handles struct from a layer above.</p><p>How can I overcome this?</p>Mark Golberghttps://fr.mathworks.com/matlabcentral/profile/authors/6665405-mark-golbergtag:fr.mathworks.com,2005:Question/3465022017-06-27T20:23:45Z2017-06-27T20:23:45ZConvert cell array to matrix to be able to export to excel<pre class="language-matlab">if true
SaveFileName = 'Sus-Ih5';
% Get Cell selection file
[FileName,PathName] = uigetfile('*.xlsx','Select Excel file','MultiSelect','on'); % get filename
FFN = [PathName FileName];
data_fid = fopen(FFN,'rt');
PathName=[PathName 'signal files\'];
cfsdir=PathName;
% Determine how many sheets are in the selection file
[bla,sheets]=xlsfinfo(FFN);
NumSheets=numel(sheets);
%For all sheets do
for jj = 1:numel(sheets)
Excel=[];
Sheet=sheets{jj}; %Convert sheet name in string
[Excel,bla]=xlsread(FFN,Sheet); %Read content Selection File
[CellNum bla]=size(Excel); %Determine number of cells
for ii = 1:CellNum
% Clear variables
input=[];
% Read File
fName=sprintf('MA%3.3d_%3.3d.cfs',Excel(ii,1),Excel(ii,2)); %Make data filename
input=ReadCFSFile(cfsdir, fName, chan_num,0); % Dir, FileName, Records (0=all)
disp([ 'File Name: ' fName]);
</pre><pre> A(:,ii,jj)= { input.current(:,1003:3003)};</pre><pre> end
v = cell2mat(A)
% xlswrite(fullfile(PathName,SaveFileName),A(:,:,:),Sheet,'A1');
end
end</pre><p>So this is the code I am working on, this files, have 5 traces (2000 points each). I need to extract part of the data from some cells, later on subtract one cell in one condition to another. so I created A a 1x6 cell. Inside there is 6 5x2000 matrix I want to use.
I want to transform the cell into matrix, 30x2000 (in this case because there are 6 cells to analyze) or something like that, so I can do it for all, later subtract.</p><p>cell2mat(A) just transforms it 5x120006 or something like that and I can't use it.
Could anybody help.</p><p>I am sorry I am very new to this coding thing.</p>Milagros ARIETTIhttps://fr.mathworks.com/matlabcentral/profile/authors/7139067-milagros-ariettitag:fr.mathworks.com,2005:Question/3463622017-06-26T23:23:56Z2017-06-27T20:23:21ZHow do I vectorize the following the summation?<p>This is the code that I have. It's taking up way too much time so I was wondering if it is possible to 'vectorize' it, to save time. Here's the code:</p><pre class="language-matlab">Sigma=zeros(n,n);
G=zeros(n,n);
for i=1:m
Sigma=(y(i)-x(i,:)*bhat).^2*(x(i,:)).'*x(i,:)+Sigma;
G=*(x(i,:)).'*x(i,:)+G;
end
</pre><p>Where x is a mXn matrix, y is a mX1 and bhat is a nX1. I have already vectorized G but I can't get Sigma to work. My best try so far is the following.</p><pre> Sigma=x.'*(((y-x*bhat).')*(y-x*bhat))*x;
G=x.'x;</pre><p>I already realize why it is wrong, but I can't fix it. Thanks for the help in advance.</p>Cache Ellsworthhttps://fr.mathworks.com/matlabcentral/profile/authors/10469020-cache-ellsworthtag:fr.mathworks.com,2005:Question/3464942017-06-27T19:27:25Z2017-06-27T20:17:21ZWhy does ifft of a complex matrix gives me another complex matrix rather than a real one?<p>Hello,
I have two matrices (complex numbers) and tried to you ifft command on both of them. So one of them gave me a real output while other gives a complex one. Can someone please tell me why is that? Before doing that i though ifft of a complex matrix gives a real matrix.</p><p>Thank you.</p>Atharva Hanshttps://fr.mathworks.com/matlabcentral/profile/authors/7520837-atharva-hanstag:fr.mathworks.com,2005:Question/3464722017-06-27T16:28:05Z2017-06-27T20:15:21ZHow can I calculate the corrlation between columns of different timetables?<p>I'm looking at half hourly data over a year (e.g. 17568x6 for weather variables, and 17568x1 for various load and demand data timetables). I want to calculate the correlation between individual columns in my weather timetable to (generally the 1st) columns of my load/demand timetable.
I've tried</p><pre class="language-matlab">stats::correlation(timetable_weather,1,timetable_demand,1),
</pre><p>which comes up with</p><p>Error: File: CorrelationDemandandTemp.m Line: 1 Column: 7
Unexpected MATLAB operator.</p><p>And I've read through corrcoef but am not entirely sure how to adapt that to columns of different timetables (I could put the columns I'm wanting to find correlations from in the same timetable if that would help?)</p>Khadisha Zahrahttps://fr.mathworks.com/matlabcentral/profile/authors/8914485-khadisha-zahratag:fr.mathworks.com,2005:Question/3454642017-06-20T09:04:11Z2017-06-27T20:14:35Zrecurrence 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://fr.mathworks.com/matlabcentral/profile/authors/2389187-venkatatag:fr.mathworks.com,2005:Question/3464402017-06-27T13:37:45Z2017-06-27T20:08:30ZIndex 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://fr.mathworks.com/matlabcentral/profile/authors/7139067-milagros-ariettitag:fr.mathworks.com,2005:Question/3464992017-06-27T19:57:52Z2017-06-27T20:07:25ZWhat version of MATLAB should I buy if I am an undergraduate physics student?<p>When I was looking at purchasing a student license, it said it was limited to primary and secondary school students. I am currently a rising sophomore Physics candidate, with a focus in astronomy (although that is not my sole interest). What version should I buy and what types of addons would be the best for me?</p>Sean MacBridehttps://fr.mathworks.com/matlabcentral/profile/authors/10483746-sean-macbridetag:fr.mathworks.com,2005:Question/3445922017-06-13T17:10:17Z2017-06-27T20:04:13ZI need to have a user input for a certain number of vectors to be created.<p>I have a vector of ODEs (ordinary differential equations) that I use to solve with the function ode45. My task is to have a user input of 'n' that calls for 'n' number of ODEs in my code. I know how to have the user prompt for 'n', I don't know how to make the program recognize that it needs to create 'n' equations in the function file. Any thoughts?</p><p>Right now it's hard-coded to 20 equations, but I need to have it to where user input determines number of equations. There is a recognizable pattern though.</p><pre class="language-matlab">Code for reference:
</pre><pre class="language-matlab">function [ DeltaO2Concentration ] = O2Solver_beta(t,O2Conc,c,O2Leak)
%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), O2Con (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));
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));
c*t*(O2Conc(18)-O2Conc(19)+O2Conc(20)-O2Conc(19));
0];
end
</pre>Areeb Hussainhttps://fr.mathworks.com/matlabcentral/profile/authors/6072795-areeb-hussaintag:fr.mathworks.com,2005:Question/3463442017-06-26T20:09:47Z2017-06-27T20:03:28ZSimscape Multibody mutually dependant definitions<p>I'd like to model two masses that are attached by springs and dampers (picture below). I'm interested in their behavior after they are let go and acted upon by gravity.</p><img src = "/matlabcentral/answers/uploaded_files/81516/TwoMassesAttachedBySpringsAndDampers.png"><p>So far I have the following system:</p><img src = "/matlabcentral/answers/uploaded_files/81517/SimscapeProgram.JPG"><p>I get an error stating that: "Coordinate systems CS1@Body1, CS2@Body Spring & Damper2/Body1 on the highlighted Bodies have mutually dependent definitions. Remove mutual dependencies among coordinate systems so that at least one coordinate system is directly or indirectly referenced to World."</p><p>Everything online says that this error is the result of a circular definition of the coordinate system. I don't think that this is the case in my model.</p><img src = "/matlabcentral/answers/uploaded_files/81518/BodyDefinitions.JPG"><p>Does anyone know of a Simscape Multibody example that uses the Body Spring & Damper block?</p><p>Thank you very much for your help.</p>Seanhttps://fr.mathworks.com/matlabcentral/profile/authors/10033174-seantag:fr.mathworks.com,2005:Question/3463882017-06-27T06:16:28Z2017-06-27T19:56:01ZHow to make Tabs in Matlab GUI without using GUIDE?<p>does someone know how to create Tabs in Matlab GUI without using GUIDE?</p>Aleksandar Petrovhttps://fr.mathworks.com/matlabcentral/profile/authors/3525254-aleksandar-petrovtag:fr.mathworks.com,2005:Question/3464982017-06-27T19:53:44Z2017-06-27T19:53:44ZHow can i take the Oy axis of 2 functions and generate another plot with them?(show the dependence of a function from another)<p>Hello.
I got a program that uses ode 45 do calculate a differential solution for a sigma(t)(stands for stress) function useing another epsilon(t)(stand for strain) function.Now i want to take the OY axis of both function(like to plot epsilon(t) on OX axis and sigma(t) on OY axis) to show the dependence of sigma from epsilon(both being dependent on time t).I've tried searching but i do no find the exact thing i want.If i could get some help i would appreciate it.
Thanks in advance!</p><p>The program is as fallowing:</p><pre class="language-matlab">if true
% function serie_maxwell_kelvin
</pre><pre> clear all
close all</pre><pre> %ne definim functia epsilon ce reprezinta deformatia
function [z] = epsilon(t)
z=sin(t);
end</pre><pre> %definim derivatele functiei epsilon
syms t
sym_epsilon = epsilon(t);
clear d_epsilon d2_epsilon
matlabFunction( diff(sym_epsilon, t), 'vars', t, 'file', 'd_epsilon.m');
matlabFunction( diff(sym_epsilon, t, 2), 'vars', t, 'file', 'd2_epsilon.m');</pre><pre> %introducem constantele(constanta de elasticitate si modulul lui Young)
E1=input('E1=');
niu1=input('niu1=');
E2=input('E2=');
niu2=input('niu2=');</pre><pre> %calculam coeficienti pk si qk
p2=niu2/E1;
p1=1+E2/E1+niu2/niu1;
p0=E2/niu1;
q2=niu2;
q1=E2;
q0=0;</pre><pre> %ne alegem intervalul de timp pe care vom reprezenta dependenta tensiuni
t0=0;
tf=30;
N=101;
t=linspace(t0,tf,1000);</pre><pre> %introducem conditiile de racordare a datelor initiale
sigma_initial=(q2/p2)*epsilon(0);
dsigmadt_initial=(q1/p2)*epsilon(0)+ ((p1*q2)/(p2*p2))*epsilon(0)+(q2/p2)*d_epsilon(0);
%folosim functia ode45 ca sa ne rezolve ecuatia liniara de ordin superior
%asociata sistemului de ecuatii diferentiale de ordinul intai
[t,x]=ode45(@sistemul_cu_ec_de_gradul_1,t,[sigma_initial dsigmadt_initial]);</pre><pre> %afisam graficul pentru ode45
figure(1)
plot(t,x(:,1),'b','LineWidth',3);
xlabel('t');
ylabel('/sigma(t)');</pre><pre> %afisam graficul functiei de deformatie
figure(2)
plot(t,epsilon(t),'*');
xlabel('t');
ylabel('epsilon(t)');</pre><pre> %afisam graficul pentru comparare a functiei de deformatie si a tensiuni
%calculate cu ode45
figure(3)
plot(t,epsilon(t),'*');
hold on
plot(t,x(:,1),'b','LineWidth',3);
legend('deformatie','tensiune');
%calculam sistemul de ecuatii diferentiale de ordinul intai asociat
%ecuatiei liniare de ordin superior
function[dxdt]=sistemul_cu_ec_de_gradul_1(t,x)
dxdt_2=x(1);
dxdt_1=-(p1/p2)*x(1)-(p0/p2)*x(2)+(q2/p2)*d2_epsilon(t)+(q1/p2)*d_epsilon(t)+(q0/p2)*epsilon(t);
dxdt=[dxdt_1; dxdt_2];
end</pre><pre> end</pre><pre class="language-matlab">end
</pre>Milu Mihaihttps://fr.mathworks.com/matlabcentral/profile/authors/10240297-milu-mihaitag:fr.mathworks.com,2005:Question/3464962017-06-27T19:31:19Z2017-06-27T19:48:16ZI am plotting the moving median of the result of a for loop, but it is plotting multiple lines?<p>My code goes something like this</p><pre> hold on</pre><pre> For i = 1:end;</pre><pre> result(i)= calc;</pre><pre> median = movmedian(result,10);</pre><pre> plot(i,median);</pre><pre> end</pre><p>As the median is calculated, multiple lines are being plotted, proportional to the moving median range I'm using... any ideas?</p>Mark Lepagehttps://fr.mathworks.com/matlabcentral/profile/authors/10139950-mark-lepagetag:fr.mathworks.com,2005:Question/959042009-06-27T01:11:00Z2017-06-27T19:44:02ZWhy does my NI PCMCIA - 6062E 6024E 6036E crash with a blue screen when I attempt to collect analog input data with the Data Acquisition Toolbox 2.2 (R13)?<p>I am using the latest driver from National Instruments: Driver version 6.9.3f3.</p><p>The following code reproduces the problem:</p><pre class="language-matlab">ai = analoginput('nidaq',1)
</pre><pre class="language-matlab">ai.SampleRate = 1000;
ai.SamplesPerTrigger = 10*1000;
addchannel(ai,1);
</pre><pre class="language-matlab">start(ai)
</pre><pre class="language-matlab">dat = getdata(ai);
</pre><p>The same problem is reported for the NI PCMCIA-6024E and PCMCIA-6036E cards.</p>MathWorks Support Teamhttps://fr.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:fr.mathworks.com,2005:Question/3464972017-06-27T19:44:00Z2017-06-27T19:44:29ZHow do i make properties of a GUI's object applicable for multiple objects? <p>I am building a calculator app and have many edit boxes for user inputs, like this:
bla_edit = uicontrol( <b>'parent',expenses</b>,'style','edit', <b>'backgroundcolor','white'</b>,'units','normalized','position',
[0.85,0.9,0.1,0.03],'HorizontalAlignment','left','fontunits','normalized','fontsize',0.7);</p><p>there are many <b>identical</b> values among the boxes, so i wonder if there is any elegant way to put them in one place
so they will affect all the objects?</p><p>thanks in advance.</p>Kobi Itzkovichhttps://fr.mathworks.com/matlabcentral/profile/authors/9434573-kobi-itzkovichtag:fr.mathworks.com,2005:Question/3453592017-06-19T15:31:06Z2017-06-27T19:38:39ZMatching color for a reference and a sample image<img src = "/matlabcentral/answers/uploaded_files/80891/untitled.png"><p>I am trying to somehow match the colors in the 2 images attached, as I need to do this for several data sets it is not a solution to do it manually. I have tried looking at histograms and changing colors accordingly but to no real succes. Any help is appreciated :)</p><p>I realise that some of the regions are completely different from each other and it is practically impossible to match these regions in color, for the larger regions it should be possible to change this automatically.</p>Rasmus Hvasshttps://fr.mathworks.com/matlabcentral/profile/authors/4348131-rasmus-hvasstag:fr.mathworks.com,2005:Question/3121982016-11-14T19:16:02Z2017-06-27T19:36:52ZHow 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://fr.mathworks.com/matlabcentral/profile/authors/3629750-eliane-truccolotag:fr.mathworks.com,2005:Question/3459332017-06-23T02:23:31Z2017-06-27T19:33:26ZHow to store the looping plot value in to a variable ?<p>Hello</p><p>I have matlab code as follows:
How to store the looping plot value of "ColorPink" over bandnumber into one variable, so I can analyze and cluster this variable for further processing. thanks before</p><pre> for y=1:sample_nu
for x=1:band
Pinkcolor(y,:)=impixel(Color61(:,:,x),PinkColorsampling(y,1),PinkColorsampling(y,2));
ColorPink(x,:)=Pinkcolor(y,:);
end
plot(bandnumber,ColorPink(:,1),'r');hold on
end</pre>lina septianahttps://fr.mathworks.com/matlabcentral/profile/authors/8828914-lina-septianatag:fr.mathworks.com,2005:Question/3463322017-06-26T18:36:25Z2017-06-27T19:31:28ZChange x-axis label font size?<p>I just have a basic plot and I want to change the font size of only the x axis labels. All the methods I'm trying are changing the font size for both the x and y axes and the title. Any tips? Thanks!</p>jcm95https://fr.mathworks.com/matlabcentral/profile/authors/7594047-jcm95tag:fr.mathworks.com,2005:Question/960052012-02-27T22:41:00Z2017-06-27T19:29:04ZWhy do I get the error "Undefined function or variable"?<p>I am receiving the following error message, how can I resolve this issue?</p><pre class="error"> ??? Undefined function or variable ‹FunctionName›
??? Undefined function or method ‹FunctionName› for input arguments of type ‹ClassName›.</pre>MathWorks Support Teamhttps://fr.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:fr.mathworks.com,2005:Question/3464952017-06-27T19:28:42Z2017-06-27T19:28:42ZIs it possible to resize a region in a grayscale image?<p>Is it possible to resize a white blob in a grayscale image without changing anything else? If so, how can I do so? I am trying to resize the largest blob while keeping the size of the other regions the same.</p>Tiffany Maohttps://fr.mathworks.com/matlabcentral/profile/authors/10512049-tiffany-maotag:fr.mathworks.com,2005:Question/3463552017-06-26T22:13:01Z2017-06-27T19:28:27ZUnderstanding 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://fr.mathworks.com/matlabcentral/profile/authors/10278755-abichtag:fr.mathworks.com,2005:Question/3464892017-06-27T18:39:47Z2017-06-27T19:10:02Zsegment a region in image using pixel coordinates <p>I want to segment the cartilage (masked by black lines) from the knee. I have the boundary values stored in a nx2 double matrix ( 2 of them, one for the inner and one for the outer boundary).
Any help will be much appreciated!
Here is the image</p><img src = "/matlabcentral/answers/uploaded_files/81589/t.jpg">Tram Phamhttps://fr.mathworks.com/matlabcentral/profile/authors/10429920-tram-pham