https://jp.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2017-06-24T20:33:02Ztag:jp.mathworks.com,2005:Question/3461342017-06-24T20:33:02Z2017-06-24T20:33:02ZPaths search in a graph<p>I have the following code to generate a graph from a matrix :</p><pre class="language-matlab">B=randi([0 1], i*2,j);
nNodeCol = size(B,2); % one node for each column of B
nNodeLine = size(B,1)/2; % one node for every two lines of B
% First the column nodes, then the line nodes:
nodeNames = [cellstr(strcat('O', num2str((1:size(B,2))'))) ; cellstr(strcat('S', num2str((1:size(B,1)/2)')))];
% Adjacency matrix adj, adj(i,j)=1 means there is an edge from node#i to node#j:
adj = zeros(nNodeCol+nNodeLine); % square matrix which size is the number of nodes
adj(1:nNodeCol, nNodeCol+1:end) = B(1:2:end,:)'; % edge from a column node to a line node is added for all the 1 in the first line of the node in the matrix
adj(nNodeCol+1:end, 1:nNodeCol) = B(2:2:end,:); % edge from the line node to a column node is added for all the 1 in the second line of the node in the matrix
% Creation of the graph:
G = digraph(adj,nodeNames);
plot(G);
</pre><p>I want to know how can I search for a path between two nodes in G and show it ? and also how can i search for all the paths having a node n as a source ?
thank you.</p>stam dadihttps://jp.mathworks.com/matlabcentral/profile/authors/7029389-stam-daditag:jp.mathworks.com,2005:Question/3461322017-06-24T19:38:38Z2017-06-24T20:28:20ZHow to evaluate a symbolic Jacobian?<p>Dear Readers,</p><p>How do I evaluate this Jacobian for 50 different combinations of (p,c,R), calculate its eigenvalues and then plot the results against p? I've been stuck with this problem for almost three days.</p><pre class="language-matlab">syms c p R c2 p2
</pre><pre class="language-matlab">outp = (c2*p2)/(((99*R)/100 - 99/100)*(p2/p)^((2*R)/(R - 1))*(c2/c)^(R/(2*(R - 1))) + 99/100);
</pre><pre class="language-matlab">infl = (((2*c2*p2)/(35*(((99*R)/100 - 99/100)*(p2/p)^((2*R)/(R - 1))*(c2/c)^(R/(2*(R - 1))) + 99/100)) + 2/175)/(((99*R)/100 - 99/100)*(p2/p)^((2*R)/(R - 1))*(c2/c)^(R/(2*(R - 1))) + 99/100) - (99*p2)/100 + (99*p2^2)/100 + (3*((c2*p2)/(((99*R)/100 - 99/100)*(p2/p)^((2*R)/(R - 1))*(c2/c)^(R/(2*(R - 1))) + 99/100) + 1/5)^(20/7))/35 + 1/4)^(1/2) + 1/2;
</pre><pre class="language-matlab">J = [jacobian(outp, c2), jacobian(outp, p2) ; jacobian(infl, c2), jacobian(infl, p2)];
</pre><pre class="language-matlab">%%%%%%%%
</pre><pre class="language-matlab">beta = 0.99 ; v = 21 ; gamma = 350 ; eps = 1 ; g = 0.2 ; sigma = 1; alpha = 0.7;
</pre><pre class="language-matlab">c_sol = zeros(1,50);
p = linspace(0.8,1.2,50);
for i = 1 : numel(p)
pi_actual = p(i);
fun = @(c) (1 - beta)*pi_actual*(pi_actual-1) - (v/(alpha*gamma))*(c+g).^((1+eps)/alpha) - ((1-v)/gamma)*(c+g)*c.^(-sigma);
c_sol(i) = fzero(fun,0.5);
end
</pre><pre class="language-matlab">c = c_sol; c2 = c_sol; p2 = p;
R = p/beta; % interest
</pre><pre class="language-matlab">%%%%%%%
</pre><pre class="language-matlab">eigVals = zeros(2,numel(p));
</pre><pre class="language-matlab">for k = 1:numel(p)
</pre><pre> eigVals(:,k) = eig(B);</pre><pre> figure;
hold on;
plot(p, eigVals(:,k)', '*');
end</pre>Sean Bagcikhttps://jp.mathworks.com/matlabcentral/profile/authors/3420656-sean-bagciktag:jp.mathworks.com,2005:Question/3461182017-06-24T15:38:09Z2017-06-24T20:16:10ZWhat function (if any) can I use to simplify symbolic equation in terms of another variable?<img src = "/matlabcentral/answers/uploaded_files/81350/p1.JPG"><p>I would like dH3 in terms of Cv</p>Miguel Ramirezhttps://jp.mathworks.com/matlabcentral/profile/authors/8565163-miguel-ramireztag:jp.mathworks.com,2005:Question/3460062017-06-23T14:01:47Z2017-06-24T20:14:32ZWaitbar till a file is created after a process<p>Dear all,
I have a minimization function with many nested functions, inside a matlab gui. This function starts after pressing a button. So, you realise that the time for the minimization process to end is not defined. When the minimization is ended a figure is exported!
Does anyone know how to create a waitbar to count till the figure creation???
All waitbars need a loop with a step. However, the time for the minimization is different each time!
Thank you!</p>abazahttps://jp.mathworks.com/matlabcentral/profile/authors/7165029-abazatag:jp.mathworks.com,2005:Question/3460462017-06-23T18:57:00Z2017-06-24T20:13:22ZError message with 'visible' when using GUI<p>I used a GUI which was built in an older version of MATLAB. I got the error like this when I tried to run it in Matlab 2015:</p><pre class="language-matlab">Error using matlab.graphics.Graphics/set
</pre><pre class="language-matlab">The name 'visible' is not an accessible property for an instance of class
</pre><pre class="language-matlab">'matlab.graphics.GraphicsPlaceholder'.
</pre><pre class="language-matlab">Error in enablews (line 20)
</pre><pre> set(h{i}(:),'visible',state);</pre><pre class="language-matlab">Error in rcmgui (line 109)
</pre><pre> enablews(HANDLES.ws{3},'off');</pre><p>The script enablews.m is</p><pre class="language-matlab">function enablews(ws,state)
% ENABLEWS(WS,STATE) change the 'visible' attribute of the handles
% contained in WS. WS is a structure of doubles, and STATE is eiter 'on'
% or 'off'.
%
% Used by PSASS
if isempty(ws)
</pre><pre> return;</pre><pre class="language-matlab">end
</pre><pre class="language-matlab">h = struct2cell(ws); % a cell of handles
</pre><pre class="language-matlab">nh = length(h);
</pre><pre class="language-matlab">for i=1:nh
</pre><pre> if iscell(h{i})</pre><pre> set(cat(1,h{i}{:}),'visible',state);</pre><pre> else</pre><pre> set(h{i}(:),'visible',state);</pre><pre> end</pre><pre class="language-matlab">end
</pre>Chenghaohttps://jp.mathworks.com/matlabcentral/profile/authors/7386867-chenghaotag:jp.mathworks.com,2005:Question/2216262015-05-31T04:52:05Z2017-06-24T20:09:53ZWhy is my GUI program producing an error when I 'Run' it?<p>When I run the below .m file, it gives me the following error:</p><p>Error using feval
Undefined function 'frequency_axes_CreateFcn' for input arguments of type 'matlab.graphics.axis.Axes'.</p><p>Error in gui_mainfcn (line 95)
feval(varargin{:});</p><p>Error in TestInterface (line 43)
gui_mainfcn(gui_State, varargin{:});</p><p>Error in @(hObject,eventdata)TestInterface('frequency_axes_CreateFcn',hObject,eventdata,guidata(hObject))</p><p>Any idea why? Here's the code from my .m:</p><pre class="language-matlab">function varargout = TestInterface(varargin)
% TESTINTERFACE Application M-file for TestInterface.fig
% TESTINTERFACE, by itself, creates a new TESTINTERFACE or raises the existing
% singleton*.
%
% H = TESTINTERFACE returns the handle to a new TESTINTERFACE or the handle to
% the existing singleton*.
%
% TESTINTERFACE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in TESTINTERFACE.M with the given input arguments.
%
% TESTINTERFACE('Property','Value',...) creates a new TESTINTERFACE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before two_axes_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to TestInterface_OpeningFcn via varargin.
%
% *See GUI Options - GUI allows only one instance to run (singleton).
%
% See also: GUIDE, GUIDATA, GUIHANDLES
</pre><pre class="language-matlab">% Edit the above text to modify the response to help TestInterface
</pre><pre class="language-matlab">% Copyright 2001-2006 The MathWorks, Inc.
</pre><pre class="language-matlab">% Last Modified by GUIDE v2.5 31-May-2015 00:38:11
</pre><pre class="language-matlab">% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @TestInterface_OpeningFcn, ...
'gui_OutputFcn', @TestInterface_OutputFcn, ...
'gui_LayoutFcn', [], ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
</pre><pre class="language-matlab">if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
</pre><pre class="language-matlab">% --- Executes just before TestInterface is made visible.
function TestInterface_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to TestInterface (see VARARGIN)
</pre><pre class="language-matlab">% Choose default command line output for TestInterface
handles.output = hObject;
</pre><pre class="language-matlab">% Update handles structure
guidata(hObject, handles);
</pre><pre class="language-matlab">% UIWAIT makes TestInterface wait for user response (see UIRESUME)
% uiwait(handles.figure1);
</pre><pre class="language-matlab">% --- Outputs from this function are returned to the command line.
function varargout = TestInterface_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
</pre><pre class="language-matlab">% Get default command line output from handles structure
varargout{1} = handles.output;
</pre><pre class="language-matlab">% --------------------------------------------------------------------
function plot_button_Callback(hObject, eventdata, handles, varargin)
% hObject handle to plot_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(0,'DefaultFigureColor','White',...
'defaultaxesfontsize',8,...
'DefaultAxesFontname','Calibri',...
'DefaultTextFontName','Calibri')
x = [0:20];
y = [0:20];
</pre><pre class="language-matlab">% Get user input from GUI
f1 = str2double(get(handles.f1_input,'String'));
f2 = str2double(get(handles.f2_input,'String'));
constant = str2double(get(handles.constant,'String'));
</pre><pre class="language-matlab">% Calculate data
TestFormula = @(x,y)(x + y.*constant);
[X,Y] = meshgrid(x,y);
Z1 = TestFormula(X,Y);
Z2 = TestFormula(f1,f2);
</pre><pre class="language-matlab">% Create frequency plot in proper axes
%plot(handles.frequency_axes,f,m(1:257))
s1 = surf(X,Y,Z1)
set(handles.edit5,'String',Z2)
xlabel('X', 'fontweight', 'bold')
ylabel('Y', 'fontweight', 'bold')
%title('(A)', 'FontSize', 12, 'fontweight', 'bold')
view (135,15);
yh = get(gca,'YLabel'); % Handle of the y label
set(yh, 'Units', 'Normalized')
pos = get(yh, 'Position');
set(yh, 'Position',pos.*[0.85,0.6,1],'Rotation',-10.9)
xh = get(gca,'XLabel'); % Handle of the x label
set(xh, 'Units', 'Normalized')
pos = get(xh, 'Position');
set(xh, 'Position',pos.*[1,1,1],'Rotation',11.1)
zlabel('Z', 'fontweight', 'bold')
zh = get(gca,'ZLabel'); % Handle of the z label
set(zh, 'Units', 'Normalized')
pos = get(zh, 'Position');
set(zh, 'Position',pos.*[1.5,1,0],'Rotation',90)
%set(handles.frequency_axes,'XMinorTick','on')
axis tight
camlight
lighting phong
shading interp
set(s1,'FaceColor',[0 0.63 0.91], 'edgecolor',[0 0 0.4],'meshstyle','both','linewidth',.15);
grid on
</pre><pre class="language-matlab">function f1_input_Callback(hObject, eventdata, handles)
% hObject handle to f1_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
</pre><pre class="language-matlab">% Hints: get(hObject,'String') returns contents of f1_input as text
% str2double(get(hObject,'String')) returns contents of f1_input
% as a double
</pre><pre class="language-matlab">% Validate that the text in the f1 field converts to a real number
f1 = str2double(get(hObject,'String'));
if isnan(f1) || ~isreal(f1)
% isdouble returns NaN for non-numbers and f1 cannot be complex
% Disable the Plot button and change its string to say why
set(handles.plot_button,'String','Cannot plot f1')
set(handles.plot_button,'Enable','off')
% Give the edit text box focus so user can correct the error
uicontrol(hObject)
else
% Enable the Plot button with its original name
set(handles.plot_button,'String','Plot')
set(handles.plot_button,'Enable','on')
end
</pre><pre class="language-matlab">function f2_input_Callback(hObject, eventdata, handles)
% hObject handle to f2_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
</pre><pre class="language-matlab">% Hints: get(hObject,'String') returns contents of f1_input as text
% str2double(get(hObject,'String')) returns contents of f1_input
% as a double
</pre><pre class="language-matlab">% Validate that the text in the f2 field converts to a real number
f2 = str2double(get(hObject,'String'));
if isnan(f2) ... % isdouble returns NaN for non-numbers
|| ~isreal(f2) % f1 should not be complex
% Disable the Plot button and change its string to say why
set(handles.plot_button,'String','Cannot plot f2')
set(handles.plot_button,'Enable','off')
% Give the edit text box focus so user can correct the error
uicontrol(hObject)
else
% Enable the Plot button with its original name
set(handles.plot_button,'String','Plot')
set(handles.plot_button,'Enable','on')
end
</pre><pre class="language-matlab">function edit5_Callback(hObject, eventdata, handles)
% hObject handle to edit5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
</pre><pre class="language-matlab">% Hints: get(hObject,'String') returns contents of edit5 as text
% str2double(get(hObject,'String')) returns contents of edit5 as a double
</pre><pre class="language-matlab">% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
</pre><pre class="language-matlab">% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
</pre><pre class="language-matlab">function constant_Callback(hObject, eventdata, handles)
% hObject handle to constant (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
</pre><pre class="language-matlab">% Hints: get(hObject,'String') returns contents of constant as text
% str2double(get(hObject,'String')) returns contents of constant as a double
constant = str2double(get(hObject,'String'));
if isnan(constant) ... % isdouble returns NaN for non-numbers
|| ~isreal(constant) % f1 should not be complex
% Disable the Plot button and change its string to say why
set(handles.plot_button,'String','Cannot plot constant')
set(handles.plot_button,'Enable','off')
% Give the edit text box focus so user can correct the error
uicontrol(hObject)
else
% Enable the Plot button with its original name
set(handles.plot_button,'String','Plot')
set(handles.plot_button,'Enable','on')
end
</pre><pre class="language-matlab">% --- Executes during object creation, after setting all properties.
function constant_CreateFcn(hObject, eventdata, handles)
% hObject handle to constant (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
</pre><pre class="language-matlab">% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
</pre>Ahttps://jp.mathworks.com/matlabcentral/profile/authors/4874440-atag:jp.mathworks.com,2005:Question/3461212017-06-24T18:00:55Z2017-06-24T20:09:48ZNeed help with loops<p>I have written a script that reads in data from an excel file into a 4x27 matrix and then performs all the relevant analysis I need and displays results in the command window. I am happy with the script, but I have large amounts of data to run through.</p><p>All the data is in the identical form (a 4x27 matrix) but it has to be copied and pasted from a webpage into the excel sheet. At the moment I am running the script for seperate excel sheets, but would like to copy and paste multiple data sets into the excel sheet and run the script once to get all the data.</p><p>i.e. the script currently reads in rows like:</p><p>data1</p><p>data1</p><p>data1</p><p>data1</p><p>then I have to manually create another excel file/overwrite the existing file to create more data. I want it to deal with:</p><p>data1</p><p>data1</p><p>data1</p><p>data1</p><p>data2</p><p>data2</p><p>data2</p><p>data2</p><p>etc......</p><p>I feel that since I have already read the script to deal with each dataset as i desire, this shouldn't be a hard task to perform if I use loops well. I just have an almost non-existent knowledge of how to use loops.</p><p>I was hoping people could point me in the right direction.</p><p>Any help would be great thanks.</p>Adam Cookhttps://jp.mathworks.com/matlabcentral/profile/authors/8541773-adam-cooktag:jp.mathworks.com,2005:Question/3461332017-06-24T20:06:36Z2017-06-24T20:06:36Zhow 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:
Error using mexopencv.make>pkg_config (line 316)
OpenCV library path not found: C:\opencv\build\x64\vc10\lib</p><p>Error in mexopencv.make>mex_options (line 256)
[cv_cflags, cv_libs] = pkg_config(opts);</p><p>Error in mexopencv.make (line 81)
mex_flags = mex_options(opts);</p><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
thanks</p>ANKIT DADHICHhttps://jp.mathworks.com/matlabcentral/profile/authors/10400427-ankit-dadhichtag:jp.mathworks.com,2005:Question/3461222017-06-24T18:07:12Z2017-06-24T20:06:22Znormalization 0 and 1 in matlab imported from excel just for one row<p>3 4 1 2 3 5 4</p>Emmanuel Fajuyigbehttps://jp.mathworks.com/matlabcentral/profile/authors/10261441-emmanuel-fajuyigbetag:jp.mathworks.com,2005:Question/3460662017-06-23T22:01:12Z2017-06-24T20:05:10ZUsing the unwrap command<p>Hi!
I'm working with a Radar image and I want to unwrap the interferometric phase of the image. I'm using the unwrap command but when I plot the image, the image is not correct. If I choose a random column on the image, I'm able to plot the unwrapped phase but what I want to do is plot unwrapped phase of the entire image. Can somebody help me with this?</p>Agustinhttps://jp.mathworks.com/matlabcentral/profile/authors/5558144-agustintag:jp.mathworks.com,2005:Question/2898832016-06-14T21:07:09Z2017-06-24T19:58:27ZFast FIFO Array/Other Datatype<p>I'm trying to plot something in real time using an FIFO array. I'm implementing the array using the advice someone else here gave me (thank you!) of the following sort:</p><pre class="language-matlab">array = {1,2,3,4};
array = array(2:end)
array{end+1} = 5
</pre><p>Unfortunately this is a bit too slow for what I'm trying to do :(. Could anyone suggest either an efficient FIFO array-like data structure? Or just a faster way?</p>Matthew Mellorhttps://jp.mathworks.com/matlabcentral/profile/authors/4592396-matthew-mellortag:jp.mathworks.com,2005:Question/3455312017-06-20T16:00:19Z2017-06-24T19:45:10Zi have a problem in arabic handwritting recognition, no error from the codes but the outputs are wrong. what possibly the cause of it?<p>the app goal is to recognize what letters that an image arabic word contains. the input is an image of arabic handwritting, it contains 3 arabic letters. the system will divide the image to 3 parts. the first letter, the middle letter, and the last letter of the word on the input image. the system will convert that 3 cropped images into binary template then it will do recognition what letter it is by comparing the cropped images to 3 different databases that contain arabic image templates(the first letter will be compared to a template database for first arabic letters, the middle will be compared to a template database for middle arabic letters, the last letter compared to a template database for last arabic letters). the output will be displayed on a text box as alphabet letters, not arabic letters (the output will be like: ta not ت). the problem is the output is totally wrong, like it should be ta but the system output will be other letter. no error in the codes by the way. FYI: an arabic letter will be shaped differently based on where it placed on an arabic word. sorry for my terrible english.</p>Alfio Rezikahttps://jp.mathworks.com/matlabcentral/profile/authors/8273523-alfio-rezikatag:jp.mathworks.com,2005:Question/3461312017-06-24T19:36:44Z2017-06-24T19:36:44ZHow to unmix signals using spectral deconvolution <p>I have data that consists of videos taken with 4 different ccd cameras, each of which records a different fluorescence wavelength.</p><p>At the moment the main contribution to each camera's signal is from its target wavelength, but each one also contains a certain contribution from the other 3 wavelengths.</p><p>I need to write a MATLAB script to perform spectral deconvolution on these data to unmix the signals such that each video only contains data from one wavelength. I can't find any inbuilt MATLAB scripts to do this, and there don't seem to be any relevant publically available toolboxes.</p><p>NB I don't know a priori the exact relative spectral response per wavelength of each channel, so I need to try blind separation. It is possible that there are some constraints (estimated contribution of each physiological signal type to each measurement channel) to facilitate the blind separation.</p>Rickhttps://jp.mathworks.com/matlabcentral/profile/authors/3998957-ricktag:jp.mathworks.com,2005:Question/3460832017-06-24T05:29:51Z2017-06-24T19:33:45ZHow to detect noisy data / outliers? <p>Hi</p><p>I have a problem to distinguish between a complete noisy data or data containing some outliers. In fact, I am trying to do a sort of Grid Independence Check (term usually is used in Computational Fluid Dynamics to identify the greed size where the numerical results are independent from the grid/network size) for my data set. I introduced this term only to better explain my case: I have a model which outputs a set of numerical data. Changing the step size in the model, increases the size of output numerical result (obviously). However, the output results contain noisy data which should be removed prior to the check for grid independence (or step size independence). An example output from the model can be similar to the following image.</p><img src = "/matlabcentral/answers/uploaded_files/81321/untitled1.png"><p>These output data points are "independent" from the step size, because the overall data (after removing the outliers) follow a linear relation independent of the steps. However, this can be detected after removal of outlier points (if not a robust criteria to check the linear relation for various step sizes would not be available; here, I use Pearson/Spearman correlations). Removing outliers from the data set shown above, can be achieved by employing MATLAB built-in function <tt>stdfilt()</tt> or simply:</p><pre class="language-matlab">rmvIdx = (abs(DataPoints- median(DataPoints)) > N*mad(DataPoints));
DataPoints(rmvIdx) = [];
</pre><p>Nevertheless, both the approaches miss some data points, and cannot "completely" detect outliers. Therefore, my first question is: how to fully detect outliers in the depicted image. I followed several variations to fully detect the outliers, e.g.:</p><pre class="language-matlab">% First remove distant outliers with N = 3
rmvIdx = (abs(DataPoints- median(DataPoints)) > N*mad(DataPoints));
DataPoints(rmvIdx) = [];
</pre><pre class="language-matlab">% Remove using local SD
Local_std = stdfilt(DataPoints);
Local_std(abs(Local_std- mode(Local_std)) < 1e-4) = 0;
DataPoints(Local_std) = [];
</pre><pre class="language-matlab">% Smoothing data as a further step
DataPoints= smooth(DataPoints,0.6);
</pre><p>The above approach will find more outliers, however this "strict" search of outliers may cause issue with other data sets, such as:</p><img src = "/matlabcentral/answers/uploaded_files/81322/untitled.png"><p>As shown, this set of data is "completely noisy" (compared to the previous image); however, when using the above-mentioned approach to detect outliers, it will erroneously detect linear relationship (Spearman/Spearman R > 0.9-0.99) for small step sizes (simply because in small step sizes noisy data may be damped by the approach I took). Thus the second questions is: how to detect completely noisy data sets, specially when I used that "strict" approach to find outliers? how to trade-off between these different but highly dependent cases?</p><p>Thanks in advance.</p>Ive Ivehttps://jp.mathworks.com/matlabcentral/profile/authors/3399872-ive-ivetag:jp.mathworks.com,2005:Question/3461252017-06-24T18:33:00Z2017-06-24T19:33:30ZError while opening R2017<p>On double-clicking on MATLAB icon a login window appears. After entering the details and pressing the "OK" button it says "An error has occurred". What to do?</p><img src = "/matlabcentral/answers/uploaded_files/81355/Capture.PNG">Subhamoy Sahahttps://jp.mathworks.com/matlabcentral/profile/authors/10519262-subhamoy-sahatag:jp.mathworks.com,2005:Question/3461302017-06-24T19:33:00Z2017-06-24T19:33:00Zgevp problem for ilmi algorithm<p>Hi. I am trying to solve the iterative lmi algorithm using gevp command in matlab. in part of the algorithm it says:</p><p>-------------------------------------------------------------------------</p><p>1. A,B,C the state matrices are realized first.</p><p>2. Q>0 is selected and a ARE is solved for the unknown P
A'P+PA-PBB'P+Q=0</p><p>3.Iteration starts i=1 and X(i)=P(obtained from above step); Three unknowns are there: P(i), F, alpha(i)( a scalar)</p><p>4.Solve the optimization for P(i),F,alpha(i):</p><pre> minimize alpha(i) subjected to LMI constraints:
4.1 [ A'P(i)+P(i)A - X(i)BB'P(i) - P(i)BB'X(i) + X(i)BB'X(i) - alpha(i)P(i) (B'P(i)+FC)';
B'P(i)+FC -I ] < 0
4.2 P(i)>0</pre><p>5. alpha(i) is obtained and checked if alpha(i)<=0</p><p>-----------------------------------------------------------------</p><p>so I have written the following code:(Matrix A is 4*4 and Matrix B is 4*1 and Matrix C is 3*4 in my problem)</p><p>setlmis([]);</p><p>P=lmivar(1,[4 1]);</p><p>F=lmivar(2,[1 3]);</p><p>lmiterm([1 1 1 0],0)</p><p>lmiterm([-1 1 1 P],1,1)</p><p>lmiterm([2 1 1 P],1,A','s')</p><p>lmiterm([2 1 1 P],-1,(B*B')*X,'s')</p><p>lmiterm([2 1 1 0],X*(B*B')*X)</p><p>lmiterm([2 2 1 P],B',1)</p><p>lmiterm([2 2 1 F],1,C)</p><p>lmiterm([2 2 2 0],-1)</p><p>lmiterm([-2 1 1 P],1,1)</p><p>lmiterm([-2 2 1 0],zeros(1,4))</p><p>lmiterm([-2 2 2 0],zeros(1,1))</p><p>lmis = getlmis;</p><p>[alpha,popt]=gevp(lmis,2)</p><p>-----------------------------------------------------------</p><p>but MATLAB says:</p><p><b>*</b> ill-posed problem: the constraint B(x) > 0 might be missing.</p><p>Result: could not establish feasibility nor infeasibility</p><p>-------------------------------------------------------------------------</p><p>What is the problem of my code??? Thanks in advance.</p>Mohsen Jorjanihttps://jp.mathworks.com/matlabcentral/profile/authors/9669866-mohsen-jorjanitag:jp.mathworks.com,2005:Question/3461292017-06-24T19:11:37Z2017-06-24T19:28:39ZHow Matlab Can Interact With Windows?!<p>Hi
i wanna write a program which if a color in the screen changed (if a pixel color changed from black to brown for example) (for example a window moved or open or someone worked with windows or ...) then matlab press a key for example the left arrow key or right arrow key.
how can i do that?!</p>Mahan Vaezzadehhttps://jp.mathworks.com/matlabcentral/profile/authors/10519530-mahan-vaezzadehtag:jp.mathworks.com,2005:Question/3461282017-06-24T19:04:13Z2017-06-24T19:23:44ZHow Can I Write A Program Pressing a Key?<p>Hi
i'm going to to use matlab for pressing keys when something changed in the screen (left arrow and right arrow keys specially), so what can i do for this?
thanks</p>Mahan Vaezzadehhttps://jp.mathworks.com/matlabcentral/profile/authors/10519530-mahan-vaezzadehtag:jp.mathworks.com,2005:Question/971012009-06-27T01:11:00Z2017-06-24T19:21:03ZHow do I remove the border lines surrounding an axes?<p>When I make a simple plot, I would like to turn off the border around the axes. However,</p><pre class="language-matlab">box off
</pre><p>removes only part of the border. I have removed all of the tick marks and labels, but there are still 2 border lines present. Is there a way to remove them?</p><p>You can reproduce the issue as follows:</p><pre class="language-matlab">hAx = axes;
</pre><pre class="language-matlab">set(hAx, 'box','off','XTickLabel',[],'XTick',[],'YTickLabel',[],'YTick',[])
</pre>MathWorks Support Teamhttps://jp.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:jp.mathworks.com,2005:Question/3461272017-06-24T19:02:03Z2017-06-24T19:17:45ZHow to save a variable length vector iterating in a loop into an Array<p>Hi,</p><p>I was trying to do some detection using the code below</p><pre> % generate total area
zone_dev=zeros(ndev);
area_zone=ndev/100;
% dev_zone=reshape(dev_num,[],area_zone);
% depth_dev_zone=reshape(depth,[],area_zone);
zone=1;
while(zone<=(ndev/100))
% cood_zone(1,zone)=round(mean(dev_zone(:,zone)))+10*randi(zone)
found=dev(dev<zone*100 & dev>(zone-1)*100))'
% if zone==0
% zone_dev_zone=[found]
% else
% zone_dev_zone=[zone_dev_zone,found]
% end
zone=zone+1;
end
Msr</pre><p>However, as the variable found is a column vector of random size, found is overridden with the current loop values.</p><p>Can someone guide me further in saving these values into an Array/List/Table.</p><p>Thanks in Advance :)</p><p>Ayan</p>Ayyangar Narasimhahttps://jp.mathworks.com/matlabcentral/profile/authors/7131781-ayyangar-narasimhatag:jp.mathworks.com,2005:Question/3461262017-06-24T19:00:05Z2017-06-24T19:00:05Zhow do i increase the maximum number of iterations for linprog?<p>Since it says to increase options.MaxIter.
I did:
OPTIONS=optimset('MaxIter',10000);
[X,FVAL,EXITFLAG,OUTPUT,LAMBDA]=linprog(c,A,b,Aeq,beq,LB,UB,OPTIONS)
Then i get erros message as:
Error using linprog (line 144)
LINPROG requires the following inputs to be of data type double: 'X0'.</p><p>Error in main_compositeSystem (line 134)
[X,FVAL,EXITFLAG,OUTPUT,LAMBDA]=linprog(c,A,b,Aeq,beq,LB,UB,OPTIONS);%,OPTIONS.MaxIter);</p><p>Turns out, linprog doesnot allow to set options??</p>Saket Adhikarihttps://jp.mathworks.com/matlabcentral/profile/authors/8240575-saket-adhikaritag:jp.mathworks.com,2005:Question/3460542017-06-23T20:06:39Z2017-06-24T18:53:37Zhow can i solve this equation for t , knowing all other variables ?<pre class="language-matlab">d_ball=147*10^-3;%m
mass=1.52;%kg
g=9.81;
Cd_sphere=1; %!!
rho=1.225;
area=pi*(d_ball^2);
k=(Cd_sphere*rho*area)/(2*mass);
y=0:1:150;
V=25;
N=g./k;
Q=g./(k.^2);
(N.*t)-(Q.*(1-exp(-k*t)))-y=0
</pre>mostafa katohttps://jp.mathworks.com/matlabcentral/profile/authors/9774310-mostafa-katotag:jp.mathworks.com,2005:Question/3461162017-06-24T14:36:32Z2017-06-24T18:48:18ZMeasuring cell migration in matlab<p>Hi all,</p><p>I have recently started doing scratch assays to measure cell migration in control and drug-treated conditions. I was hoping to use matlab to analyse the images I have taken but I'm not sure where to start (my matlab knowledge is certainly not the best!).</p><p>My experimental set up involves scratching a cross into the wells of plates containing an adherent cell line. I want to use matlab to measure cell migration and think this could be done in two ways (though please correct me if I'm wrong!):
1. Somehow measure the percent of the image which is covered by cells and compare the percentage at different time points.
2. Measure the distance travelled by the leading edge of cells and compare this distance at different time points.</p><p>My images are in a jpeg format. Could anybody please help me on how I could implement these two measures using matlab? I'd be interested to try both to see how they compare too.</p><p>Thank you in advance,
Becky</p>Becky Joneshttps://jp.mathworks.com/matlabcentral/profile/authors/10501935-becky-jonestag:jp.mathworks.com,2005:Question/3461232017-06-24T18:15:07Z2017-06-24T18:15:07ZHow to make an Amplitude Spectrum Plot of the fourier series: 1 + (2/pi) * symsum(((cos((2n-1)*pi*x-pi/2)*(1/(2*n-1)))),n,1,50)<p>f = 1 + (2/pi) * symsum(((cos((2n-1)*pi*x-pi/2)*(1/(2*n-1)))),n,1,50)</p>Lucas Mancinellihttps://jp.mathworks.com/matlabcentral/profile/authors/9535272-lucas-mancinellitag:jp.mathworks.com,2005:Question/3461202017-06-24T17:20:42Z2017-06-24T17:57:36ZAccelerometer Spectral Noise Simulation<p>Hello,
how I can create a spectral noise to simulate the spectral noise of an accelorometer?
For examples a value of 15ug/(Hz)^1/2</p><p>Thanks</p>stefano nobilihttps://jp.mathworks.com/matlabcentral/profile/authors/9340808-stefano-nobilitag:jp.mathworks.com,2005:Question/1733562015-01-30T06:33:12Z2017-06-24T17:56:50ZFind the values(coefficient) of the cubic polynomial <p>Find the values of a, b, c, and d so that the cubic polynomial y = ax3 + bx2 + cx + d provides the best fit to the following (x, y) pairs in the least squares sense: (-1, -7), (0, 4), (1, 9), (2, 2), (3, 6), (4, 16).</p><p>Note that to check your answer you can plot the given points together with your cubic polynomial on the same graph, and check to see that all 6 points lie fairly close to the curve (as in the tutorial file). But note that the curve might not pass directly through any of the 6 points.</p>you wuhttps://jp.mathworks.com/matlabcentral/profile/authors/6063607-you-wutag:jp.mathworks.com,2005:Question/3456672017-06-21T13:11:04Z2017-06-24T17:39:07ZOptimize RAM cost by only storing upper triangular part of a symmetric matrix?<p>Hi all,</p><p>I have some symmetric (almost dense) matrices which I wish to store only the upper triangular part such that I can optimize the usage of RAM. I did some experiments in MATLAB:</p><pre class="language-matlab">>> testa = rand(1000);
>> vsize(testa)
% -------------------------
% 8000000 8000000 B * testa = 2:1000x1000:double
>> testb = triu(testa);
>> testb = sparse(testb);
>> vsize(testb)
% -------------------------
% 8016008 8016008 B * testb = 2:1000x1000:double.sparse
</pre><p>We can see that after triu and sparse, storage even increased. I know that when store sparse matrix, each entry cost 8 bytes, storing x-y coordinates cost 8+8 = 16 bytes, so each entry costs 3*8 = 24 bytes, Now that in testb only half number of elements are stored, therefore the cost should be 24 * 1000 * 1000 / 2 = 12000000 bytes, so why is it 8016008 bytes in this case?</p><p>Is there a way, say I tell MATLAB that the matrix is symmetric, so I only store half entries, but do not store the x-y coordinates, such that the memory cost is exactly half of the dense matrix?</p><p>Thanks!</p>Xh Duhttps://jp.mathworks.com/matlabcentral/profile/authors/6684822-xh-dutag:jp.mathworks.com,2005:Question/2731572016-03-13T04:09:01Z2017-06-24T17:33:43Zmatlab code for multiexposure and multifocus image fusion<p>I Was doing project on multi exposure and multi focus image fusion,please help me to get the coding in matlab.</p>HEMASREE Nhttps://jp.mathworks.com/matlabcentral/profile/authors/7831595-hemasree-ntag:jp.mathworks.com,2005:Question/3459812017-06-23T10:53:49Z2017-06-24T17:32:13ZKalman filter for beginners<p>Hi,</p><p>I have never used matlab before and unfortunately don't have time to learn it in-depth so was wondering if someone could help guide me through my problem.</p><p>I have an excel spread sheet with over 50,000+ GPS fixes taken each second of decimal degree latitude and longitude locations. (a birds movement) and I am looking to kalman filter this. Is anyone able to guide me in importing this excel data and then applying a kalman filer? I would be incredibly greatful.</p><p>This is how my data looks:</p><pre class="language-matlab">Date Time Latitude Longitude
6/12/2017 12:25:00 50.774715 -3.932923
6/12/2017 12:25:01 50.774742 -3.932912
6/12/2017 12:25:02 50.774773 -3.932896
</pre>Jessica Witthttps://jp.mathworks.com/matlabcentral/profile/authors/10512734-jessica-witttag:jp.mathworks.com,2005:Question/2972682016-07-26T17:07:56Z2017-06-24T17:19:47Zhow to Solve differential equation<p>Hi all</p><p>I have equation like this</p><p>dy/dt = a*y^2 + b*y + c</p><p>where a, b and c are constant</p><p>how can I solve this equation using matlab</p>jonehttps://jp.mathworks.com/matlabcentral/profile/authors/5081265-jonetag:jp.mathworks.com,2005:Question/3428622017-06-01T13:13:50Z2017-06-24T16:58:13ZExplicit solution could not be found.. > In dsolve at 194<p>here is my code :</p><p>>>sums u(t) v(t)</p><p>>>ode1= diff(u)==u^2/v - u</p><p>>>ode2= diff(v) == u^2-v</p><p>>>odes=[ode1;ode2]</p>siddharth tripathihttps://jp.mathworks.com/matlabcentral/profile/authors/8337781-siddharth-tripathitag:jp.mathworks.com,2005:Question/623072013-02-05T11:32:01Z2017-06-24T16:44:10ZThe CLASS function must be called from a class constructor.<p>I'm currently working on a project involving some automatic differentiation, and was presented an example code to such an approach. My problems really boil down to me never working with OOD in Matlab before and it seems really overwhelming. The first part of the code looks like this, fairly straight forward. The problem is it won't run past the last line.</p><pre class="language-matlab">function ad = autodiff(val, der)
% A naive autodiff constructor.
ad.val = val;
if nargin == 1
der = 0.0;
end
if strcmp(der,'variable')
der = 1.0;
end
ad.der = der;
ad = class(ad, 'autodiff');
</pre><p>I get the error 'The CLASS function must be called from a class constructor', which I do not know how to deal with. How do I create custom classes and then call upon them later?</p><p>thanks in advance,
Kristian</p>Kristian Jørgensenhttps://jp.mathworks.com/matlabcentral/profile/authors/3317045-kristian-jorgensentag:jp.mathworks.com,2005:Question/3460132017-06-23T14:23:41Z2017-06-24T16:37:24ZPlease I want to modify that code for run length to work on gray scale image<pre> ------------------------------------------------------------------------ </pre><p>I want to modify that code to make it work on grayscale image not binary image can anyone help me</p><p>----------------------------------------------------------------------------------</p><pre class="language-matlab">function out=rle(image)
%
% RLE(IMAGE) produces a vector containing the run-length encoding of
% IMAGE, which should be a binary image. The image is set out as a long
% row, and the conde contains the number of zeros, followed by the number
% of ones, alternating.
%
% Example:
%
% rle([1 1 1 0 0;0 0 1 1 1;1 1 0 0 0])
%
% ans =
%
% 03453
%
level = graythresh(image);
BW = im2bw(image, level);
L=prod(size(BW));
im=reshape(BW',1,L);
x=1;
out=[];
while L ~= 0,
temp=min(find(im == x));
if isempty(temp),
out=[out L];
break
end;
out=[out temp-1];
x=1-x;
im=im(temp:L);
L=L-temp+1;
end;
</pre><p>------------------------------------------------------------------------</p><p>Please I want to modify that code to make it work on grayscale image not binary image can anyone help me</p>haithem abdelghanyhttps://jp.mathworks.com/matlabcentral/profile/authors/6195722-haithem-abdelghanytag:jp.mathworks.com,2005:Question/3461082017-06-24T13:04:26Z2017-06-24T16:17:16ZI have an 2014b executable that I want to run on a new PC which does not have MATLAB installed on it. I have downloaded and installed MCR_R2014b_win64_installer. when I run the executable i get this error "mclmcr initialization failed". Any thoughts?<p>mclmcr initialization failed error</p>Robert Vandeveldehttps://jp.mathworks.com/matlabcentral/profile/authors/9542029-robert-vandeveldetag:jp.mathworks.com,2005:Question/3460962017-06-24T08:21:26Z2017-06-24T16:09:21Zwhy do i recieve Index exceeds matrix dimensions error ?<p>Hi</p><p>im trying to calculate 70 different variables FDOST to do this i tried to put them in a for loop like this :</p><pre class="language-matlab">for i=1:70
for j=1:3
b(i)=FOST_1D_DEC(a(i(x:aa,j)));
end
if i>=5
x=x+5;
end
end
</pre><p>first i put all 70 variables to a variable named "a" by the command a=[ ] , as my variables are about 40001x3 , "a" becomes 40001x210 .</p><p>i want to calculate FDOST for each variable from different starting point for example :</p><pre class="language-matlab">b=FOST_1D_DEC(a1(20280:20280+1023,1));
</pre><p>but all the time i run my script i receive index matrix error. Another problem is that as i checked a(1) is not matrix with dimension of 40001x3 anymore and to solve it it should return a matrix with dimension of 40001x3, could anyone give me a suggestion how to solve the problem ???</p><p>p.s: x variable is defined by the user for example 20280 and as FDOST only works with multiplies of two i add x with 1023 which gives me aa like this aa=x+1023 another things to explain is that x should after each loop of j complete add with five to makes starting point different</p>HamidReza Salehhttps://jp.mathworks.com/matlabcentral/profile/authors/8603924-hamidreza-salehtag:jp.mathworks.com,2005:Question/3455552017-06-20T17:42:10Z2017-06-24T16:06:40ZBackground image polar plot<p>Hello,</p><p>I am displaying data using polarscatter, but I would like to add a background image on which the data is displayed including the polar axes.
My image is still a normal carthesian image and I would think I would somehow have to convert this to a round polar image before my polarscatter plot can be added.</p><p>Any help would be extremely useful.
Thanks in advance!</p><p>Regards, Luuk</p>Luuk Poorthttps://jp.mathworks.com/matlabcentral/profile/authors/5564181-luuk-poorttag:jp.mathworks.com,2005:Question/3459352017-06-23T03:34:50Z2017-06-24T15:55:33ZPromblem in GUI Error while evaluating DestroyedObject Callback<p>Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)webcam1('exit_Callback',hObject,eventdata,guidata(hObject)) <b>Error using imaqdevice/getdata (line 141)</b> <b>Error while evaluating DestroyedObject Callback</b></p><p><b>Error using matlab.ui.control.UIControl/set
Invalid or deleted object.</b> when press Exit</p><img src = "/matlabcentral/answers/uploaded_files/81226/2017-06-22_134312.png">Adisorn Phanukthonghttps://jp.mathworks.com/matlabcentral/profile/authors/6937939-adisorn-phanukthongtag:jp.mathworks.com,2005:Question/3461192017-06-24T15:43:29Z2017-06-24T15:53:12ZI am trying to calculate the mPSNR between two hdr images using HDRToolbox , but I don't knew how to fix error<p>Undefined function or method 'lum' for input arguments of type 'char'.</p>oumaima yahyaouihttps://jp.mathworks.com/matlabcentral/profile/authors/10224471-oumaima-yahyaouitag:jp.mathworks.com,2005:Question/3419522017-05-25T17:22:56Z2017-06-24T15:48:42Zwhy my stand alone toolbox is not working ?<p>2 months ago, I developed standalone toolbox by using deployment toolbox of Matlab. I tested those toolboxes on the computer where the Matlab was not installed, it was working properly. Now I try to use the toolbox again but it is not opening and not showing any error message. What is wrong with that? How can I solve that problem? Please help me to solve the problem.</p>sheli whitsonhttps://jp.mathworks.com/matlabcentral/profile/authors/7660658-sheli-whitsontag:jp.mathworks.com,2005:Question/3446562017-06-14T00:46:54Z2017-06-24T15:37:31ZHow to correlate image features<p>Helo guys help me with MATLAB code for correlating database images in which four feature were extacted.</p>Adodo Raymondhttps://jp.mathworks.com/matlabcentral/profile/authors/10472170-adodo-raymondtag:jp.mathworks.com,2005:Question/3453432017-06-19T13:46:54Z2017-06-24T15:34:10ZHow can I flexibly identify which check boxes are marked in a scanned document in the best way?<p>I am developing a program that processes scanned contracts and I want to extract some information from them. In these contracts there are several check boxes that may have been hand marked with an "X". I want to know which check boxes are marked and what information they represent. The issue is that there are several different versions of these contracts, so it is not just a simple matter of manually locating these check boxes and developing a "hard-coded" solution. I have to:</p><ol><li>Loop through the contract files (which are binary images located in a database as .tif images)</li><li>For each contract, identify which contract type it is</li><li>Given 2), run an algorithm to extract the important information from this contract</li></ol><p>My current idea of strategy for 2) is to use some kind of correlation by referencing every loaded contract against a library of all possible templates. However, since the scanned contracts might be slightly different in size, corr2 is not working very well unless I use some indexing in one of the images, i.e. something like corr2(I(1:xsize(J),1:ysize(J)),J), but I'm not sure if that's a good idea. Is there a smarter way to do this, i.e. maybe using xcorr?</p><p>For issue 3) I have adapted a modified version of the object recognition algorithm given by ImageAnalyst here <a href = "https://se.mathworks.com/matlabcentral/answers/156559-detect-horizontal-and-vertical-lines">https://se.mathworks.com/matlabcentral/answers/156559-detect-horizontal-and-vertical-lines</a>, where my idea is to identify the check boxes and use their location to identify what information they represent. I am using regionprops with bounding boxes to find my check boxes. Given these bounding boxes, I use some measures like height, eccentricity and aspect ratio to find the check boxes. It works fine, but unless I use very hard-coded constraints to identify the check boxes for each sample contract I am working on, I get instances of text identified as objects as well. See the attached image for an example ("kt" and "M" are the text instances I get). Is there a smarter way to identify these types of objects that is much more reliable? If anyone has any idea of how I can tackle this issue better it is much appreciated.</p><img src = "/matlabcentral/answers/uploaded_files/80877/identifiedboxes.jpg">SofiaHhttps://jp.mathworks.com/matlabcentral/profile/authors/6979636-sofiahtag:jp.mathworks.com,2005:Question/3460602017-06-23T20:55:44Z2017-06-24T15:30:41ZHow can I read in data and sparse each column into vectors with the saved variable name?<p>I'm trying to read in a csv file and break each column into vectors and then label each vector with the correct variable name. ( the correct variable name is saved in the csv file above each column). This is the code I have so far.</p><pre> {
asec=csvread('asec_swrat_80_16_diff.csv',1,0);
%code that reads in the first line of the csv file to grab the variable names in a vector.
[f,l]=size(asec);
for i=1:l
label(i)=asec(:,i);
end
}</pre><p>I've tried using textscan but it's not reading it into a vector format. This is the code I have for that, but again it doesn't work.</p><pre class="language-matlab">{
fid =fopen('asec_swrat_80_16_diff.csv');
label= textscan(fid,'%s',1,'HeaderLines',0);
fclose(fid);
}
</pre><p>Any help would be greatly appreciated. Thanks!</p>Cache Ellsworthhttps://jp.mathworks.com/matlabcentral/profile/authors/10469020-cache-ellsworthtag:jp.mathworks.com,2005:Question/3453252017-06-19T11:52:04Z2017-06-24T15:24:26Zhow separate color image as white ,brown and black?<p>hi there,</p><p>please anyone can help me to find a function that separate
the color image to three white,brown and black and the function return Percent of each color?</p>rachel shamulahttps://jp.mathworks.com/matlabcentral/profile/authors/10496236-rachel-shamulatag:jp.mathworks.com,2005:Question/3461112017-06-24T13:19:10Z2017-06-24T15:23:44ZUse loop for indexing <p>I'm trying to retriev an index from data by passing labels from 1 to 2
but the for loop is not changing?</p><pre> clc;
clear all;
close all;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c=2;
labels =[2,1,2,1,2,1,2,1,2,2];
data =[-26.152,0.59028;2.0480,1.1151;-16.680,0.704710;8.2308,1.1567;-14.1760,-0.879840;
7.81450,0.7927;-20.220,0.992;8.921,0.822;-16.507,0.5297;-11.212,-1.6457];
colors={'r.' 'gx' 'b+' 'ys' 'md' 'cv' 'k.' 'r*' 'g*' 'b*' 'y*' 'm*' 'c*' 'k*' };
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</pre><pre> for i=1:c
index = find(labels == i);</pre><pre> if ~isempty(index)</pre><pre> dat=data(index,:);</pre><pre> plot(dat(:,1),dat(:,2),colors{i})
end
end
for i=1:c
index=find(labels == 1);
f0(index,i)=1;
end
result.data.f=f0;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
i=2 not 1, 2 </pre>shawinhttps://jp.mathworks.com/matlabcentral/profile/authors/5290049-shawintag:jp.mathworks.com,2005:Question/3460872017-06-24T06:46:18Z2017-06-24T15:17:00Z"To RESHAPE the number of elements must not change" error during plot<p>Dear all,</p><p>I have a function (1x1 symfun) S4(t) with a variable of t. It's a very very long expression so I cannot write them here but it is a multi-exponential function.</p><p>Then I did:</p><pre class="language-matlab">t = 0:0.0000001:0.00002
y = S4(t)
plot(t,y)
</pre><p>However, I got "To RESHAPE the number of elements must not change".
I have no idea where this came from because I have never used the command RESHAPE.
Also, the first time around, when S4(t) was a slightly more compact function and rest of the script exactly the same, I did not have this issue.</p><p>I think the command "y = S4(t)" is the problem, but I don't see why it's not good.
What am I doing wrong?</p><p>Thank you</p>Hayaohttps://jp.mathworks.com/matlabcentral/profile/authors/7105253-hayaotag:jp.mathworks.com,2005:Question/3461152017-06-24T14:22:20Z2017-06-24T15:13:27ZUser input with 3 options, how to repeat question if one of the options was not entered.<p>I am trying to add something to the end of a function that will be looped over and over to ask the user whether they are happy with the results, at which they can type 'yes', 'no', or 'trash'. If the user types something else the question should be repeated until one of these options is entered. I tried to use the code:</p><pre class="language-matlab">UI = 'aaa'
while UI ~= 'yes' & UI ~= 'no' & UI ~= 'trash' %ERROR AT THIS LINE
UI = input("Are you happy with this? Enter: 'yes' 'no'(to manually change) or 'trash' skip and move onto next unit.", 's')
end
if UI == 'yes'
% do something
return
elseif UI == 'no'
% do something
else UI == 'trash'
% do something else
end
</pre><p>I have tried the while loop with both '&' and '&&' and neither works, was wondering if anyone could help me out, thanks.</p>Sean Cragghttps://jp.mathworks.com/matlabcentral/profile/authors/9577173-sean-craggtag:jp.mathworks.com,2005:Question/3460752017-06-24T03:57:28Z2017-06-24T14:59:59ZOperation on 3 dimension matrix <p>Hi
I have two 3-dimension matrices A(N,M,P) and B(M,N,P). I want to calculate the multiplication along two dimensions, that is</p><pre> for ii=1:P
C(:,:,ii) = A(:,:,ii)*B(:,:,ii);
end</pre><p>Is there any solution to achieve the above computation without for loop?</p><p>Thanks</p><p>Rui</p>Rui Caohttps://jp.mathworks.com/matlabcentral/profile/authors/9826458-rui-caotag:jp.mathworks.com,2005:Question/3461102017-06-24T13:18:07Z2017-06-24T14:55:29ZHow to set multiple pause() in a for-loop?<p>I am trying to create an animation using 3 types of plot. After each of them I want to set a pause. My code looks like this:</p><pre> for i= :
p1=plot1();
pause(delay1);
p2=plot2();
pause(delay2);
p3=plot3();
pause(delay3);
delete(p1);
delete(p2);
delete(p3);
drawnow
handles = guidata(hObject);
end</pre><p>The problem is that the pauses get sumed and when the code ritch plot 3 is a very big delay.
Can you help me whith this situation?</p>Silviu Caramidaruhttps://jp.mathworks.com/matlabcentral/profile/authors/9099731-silviu-caramidarutag:jp.mathworks.com,2005:Question/1223472014-03-20T06:34:02Z2017-06-24T14:54:18ZMatlab/Editor windows and fonts resize (get smaller) on right click ... why?<p>Hi There,</p><p>I am using MATLAB 2013b (64bit) on a Windows convertible laptop (Win 8.1 - 64bit).</p><p>When the MATLAB runs at the beginning the size of the windows and fonts are all normal compared to the system's font and display sizes, but once I do a right click everything gets re-sized (smaller) and I would have to restart the program to go back to normal.</p><p>If I had to explain it better, the effects are similar to "Changing the Size of all items" for display in the Windows system from 150% to 100%.</p><p>Does anybody know why this happens and if there is a fix for it?</p><p>Thank you in advanced ...
HoSsEiN</p>Hosseinhttps://jp.mathworks.com/matlabcentral/profile/authors/2953709-hosseintag:jp.mathworks.com,2005:Question/3460332017-06-23T17:49:29Z2017-06-24T14:53:40ZHow can I compute and plot in matlab the magnitude of H(z)? <img src = "/matlabcentral/answers/uploaded_files/81294/DSC_0665.JPG">Steven Reyes Ortizhttps://jp.mathworks.com/matlabcentral/profile/authors/8874302-steven-reyes-ortiz