http://www.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2016-02-08T02:03:31Ztag:www.mathworks.com,2005:Question/2670532016-02-08T01:25:03Z2016-02-08T02:03:31Zhow do i get the satellite simulation application for MATLAB R2014a version<p>I am a M.sc research student at FUTO Nigeria, how do i download the simulation package for satellite design and control. The version of my MATLAB is R2014a. Thanks</p>charles ezehttp://www.mathworks.com/matlabcentral/profile/authors/7501446-charles-ezetag:www.mathworks.com,2005:Question/2670552016-02-08T01:55:32Z2016-02-08T01:55:32Zswitching focus for keyboard input in a GUIDE created function<pre> I want to create a slider, after which you use it, a push button appears. However, instead of clicking the button, I want to enable the user to simply push a button on the keyboard with the same effect as pushing the pushbutton. The problem, I encounter, is that the pushbutton is not in the focus. There have been some answers out there, how to do it within the uicontrol environment. I want to know, how to do it within the GUI environment.
Here is a sample code:
function varargout = movedslider(varargin)</pre><p>gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @movedslider_OpeningFcn, ...
'gui_OutputFcn', @movedslider_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end</p><p>if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end</p><p>function movedslider_OpeningFcn(hObject, eventdata, handles, varargin)</p><p>handles.output = hObject;</p><p>guidata(hObject, handles);</p><p>function varargout = movedslider_OutputFcn(hObject, eventdata, handles)</p><p>varargout{1} = handles.output;</p><p>function slider1_Callback(hObject, eventdata, handles)
global v1 v2
v1=get(handles.slider1, 'value')
if v1~=v2
set(handles.pushbutton1,'visible','on')
end</p><p>function slider1_CreateFcn(hObject, eventdata, handles)</p><p>if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end</p><p>function pushbutton1_Callback(hObject, eventdata, handles)
global v2 v1
v2=v1;
set(handles.pushbutton1,'visible','off');</p><p>function movedslider_WindowKeyPressFcn(hObject, eventdata, handles)
keyPressed = eventdata.Key;
if strcmpi(keyPressed,'x')
uicontrol(handles.pushbutton1);
pushbutton1_Callback(handles.pushbutton1,[],handles);
end
function varargout = movedslider(varargin)</p><p>gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @movedslider_OpeningFcn, ...
'gui_OutputFcn', @movedslider_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end</p><p>if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end</p><p>function movedslider_OpeningFcn(hObject, eventdata, handles, varargin)</p><p>handles.output = hObject;</p><p>guidata(hObject, handles);</p><p>function varargout = movedslider_OutputFcn(hObject, eventdata, handles)</p><p>varargout{1} = handles.output;</p><p>function slider1_Callback(hObject, eventdata, handles)
global v1 v2
v1=get(handles.slider1, 'value')
if v1~=v2
set(handles.pushbutton1,'visible','on')
end</p><p>function slider1_CreateFcn(hObject, eventdata, handles)</p><p>if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end</p><p>function pushbutton1_Callback(hObject, eventdata, handles)
global v2 v1
v2=v1;
set(handles.pushbutton1,'visible','off');</p><p>function movedslider_WindowKeyPressFcn(hObject, eventdata, handles)
keyPressed = eventdata.Key;
if strcmpi(keyPressed,'x')
uicontrol(handles.pushbutton1);
pushbutton1_Callback(handles.pushbutton1,[],handles);
end</p><p>What do I have to change, in order to have the pushbutton1 effect while pushing 'x' on the keyboard?</p><p>Thanks!
Jan</p>Jan Meyerhttp://www.mathworks.com/matlabcentral/profile/authors/7634019-jan-meyertag:www.mathworks.com,2005:Question/2670542016-02-08T01:53:05Z2016-02-08T01:53:05ZOCR low-res image from specified set of characters<p>Hello all:</p><p>Is there a way in which I provide the super set of characters (no characters to be expected outside the set) to the OCR. I mean to say for example if I know that my images has only [U, T, C, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, :, <a href = "space">space</a>] as the only characters, can I feed it to matlab OCR and thus expect better predictions.</p><p>Can this help somehow on low res image to increase the accuracy?</p><p>Kindly see the attached image I am struggling to get good results with.</p><p>Thanks much for your attention. Any thoughts will be immensely helpful.</p><p>Regards,</p><p>Amit</p>Amithttp://www.mathworks.com/matlabcentral/profile/authors/3826444-amittag:www.mathworks.com,2005:Question/2655862016-01-28T12:21:34Z2016-02-08T01:42:45ZRead 1fps mp4 usinf videoreader or equivalent<p>I have two identical 1fps mp4 files which I want to stitch side-by-side (its 16:9 and I want a duplicate 32:9).</p><p>I am trying to use an available code, but stumbling in the first line as following:</p><pre class="language-matlab">>> vid1 = VideoReader('Left.mp4');
Error using VideoReader/init (line 457)
Failed to initialize internal resources.
</pre><pre class="language-matlab">Error in VideoReader (line 146)
obj.init(fileName);
</pre><p>This may be because my file is non-standard 1fps. Can someone help. The overall code I am trying to use if courtesy @SamuelNLP on StackOverflow and is as follows (its for avi but I have mp4):</p><pre class="language-matlab">close all
clc
clear
</pre><pre class="language-matlab">vid1 = VideoReader('video1.avi');
vid2 = VideoReader('video2.avi');
</pre><pre class="language-matlab">videoPlayer = vision.VideoPlayer;
</pre><pre class="language-matlab">% new video
outputVideo = VideoWriter('newvideo.avi');
outputVideo.FrameRate = vid1.FrameRate;
open(outputVideo);
</pre><pre class="language-matlab">while hasFrame(vid1) && hasFrame(vid2)
img1 = readFrame(vid1);
img2 = readFrame(vid2);
</pre><pre> imgt = horzcat(img1, img2);</pre><pre> % play video
step(videoPlayer, imgt);</pre><pre> % record new video
writeVideo(outputVideo, imgt);
end</pre><pre class="language-matlab">release(videoPlayer);
close(outputVideo);
</pre><p>Thanks much. Good day all.</p><p>Regards,
Amit</p>Amithttp://www.mathworks.com/matlabcentral/profile/authors/3826444-amittag:www.mathworks.com,2005:Question/2670352016-02-07T21:38:04Z2016-02-08T01:21:49ZWant to view input variables to each function evaluation in fmincon<p>Hello,</p><p>I am trying to optimize a (7-variable input) function using fmincon. I am able to optimize the function as expected but all I get at the end is the final solution of the 7 variables that result in the optimal solution of my function. This is good but I am trying to extract the input variables at every function evaluation and the result of the function evaluation into a matrix.</p><p>I am doing this so I can plot the values in a number of different ways which will show confirmation the optimization routine is working and I will be able to extract other useful data.</p><p>I have looked at modifying the fmincon function to allow this but I am having problems. I am wondering if this has been done before or if fmincon actually allows this as an output or display option?</p><p>Thank you so much</p>Steven Sonnenberghttp://www.mathworks.com/matlabcentral/profile/authors/6067433-steven-sonnenbergtag:www.mathworks.com,2005:Question/2670032016-02-07T15:58:55Z2016-02-08T01:09:04ZHigh quality spectrogram with a few seconds signal<p>I am trying to get a high quality spectrogram with a signal that is only 5 seconds long. This is the line I am using:
the sampling frequency is 1000Hz.</p><p>spectrogram(signal,128,64,2048,fs,'yaxis')</p><p>I do not get the quality I need. Is there something I could do?</p>Diana Pizarrohttp://www.mathworks.com/matlabcentral/profile/authors/6961836-diana-pizarrotag:www.mathworks.com,2005:Question/2670522016-02-08T00:58:51Z2016-02-08T01:00:43ZAccess to a table, why matlabs run with code: T = T(:,[varnames(others) 'SelfAssessedHealthStatus']); , but later can not run with this one: T(:, ['Systolic' 'Diastolic']) = [];<p>I have the code below in which 'patients.dat is a sample file in Matlab.</p><p>clear all</p><p>clc</p><p>T = readtable('patients.dat');</p><p>T(:, ['Systolic' 'Diastolic']) = [];</p><p>varnames = T.Properties.VariableNames;</p><p>others = ~strcmp('SelfAssessedHealthStatus', varnames);</p><p>T = T(:, [varnames(others) 'SelfAssessedHealthStatus']);</p><p>T(1:5,6:7)</p><p>When I run this code. Matlab reported an error message:</p><p>“ Error using magic_square (line 5)
Unrecognized variable name 'SystolicDiastolic'. “</p><p>When I remove line: T(:, ['Systolic' 'Diastolic']) = []; , matlab works well.</p><p>My problem is that: the two lines:
T = T(:, [varnames(others) 'SelfAssessedHealthStatus']);
and
T(:, ['Systolic' 'Diastolic']) = [];
Have the same syntax, but why matlab reported an error message at the latter (T(:, ['Systolic' 'Diastolic']) = [];)</p><p>Can somebody help me explain this phenomenon? many thanks and best regards!</p>Dung Lehttp://www.mathworks.com/matlabcentral/profile/authors/7460402-dung-letag:www.mathworks.com,2005:Question/2670512016-02-08T00:38:06Z2016-02-08T00:57:20ZProblems writing values from edit text box to a txt file<p>I have inserted some code under the callback function for an edit text box, it runs without any errors but when I inspect the .txt file afterwards it is blank?</p><pre class="language-matlab">endfunction edit2_Callback(hObject, eventdata, handles)
b = get(hObject,'String');
</pre><pre class="language-matlab">fid = fopen('b.txt');
</pre><pre class="language-matlab">fprintf(fid, b{:});
</pre><pre class="language-matlab">fclose(fid);
</pre><p>Originally the code was as shown below, but this gave the error 'Error using fwrite Cannot write value: unsupported class cell', adding the {:} removed this error.</p><pre> endfunction edit2_Callback(hObject, eventdata, handles)
b = get(hObject,'String');</pre><pre class="language-matlab">fid = fopen('b.txt');
</pre><pre class="language-matlab">fprintf(fid, b);
</pre><pre class="language-matlab">fclose(fid);
</pre><p>I have also tried replacing the {:} with {1}, but this still gives an empty text box?</p>Alfie Gracehttp://www.mathworks.com/matlabcentral/profile/authors/5925418-alfie-gracetag:www.mathworks.com,2005:Question/2670502016-02-08T00:34:45Z2016-02-08T00:34:45ZCan us trained Functional link neural network (FLANN) based on Levenberg-Marquardt Method?<p>Can us trained Functional link neural network (FLANN) based on Levenberg-Marquardt Method?</p>coquihttp://www.mathworks.com/matlabcentral/profile/authors/5461334-coquitag:www.mathworks.com,2005:Question/2670472016-02-07T22:46:48Z2016-02-08T00:30:47ZGenerating a heat map (or otherwise) in matlab<p>I've done simulations for an experiment to compare 2 different things, let's call them A and B. The rows of A and B correspond to different experiments. Their sizes are 100*200, so there are 100 experiments and 200 data points. These are plotted against 'trials', lets call it T, which is just 1:200. I was interested to see where along T are A and B significantly different. So, I wrote some code to determine at each instance T, are A and B significantly different.</p><p>Edit: I think what I'm looking for is "contour heat map" essentially.</p><p>That is:</p><pre class="language-matlab">for kk=1:200
[h,p]=ttest2(A(:,kk),B(:,kk),0.05);
pval(kk)=p;
hval(kk)=h; end
</pre><p>So now I have a vector p that gives me the probability that A and B are significantly different at a given instance T. What I would like to do is generate some kind of map (I guess a heat map would be approprite here? I'm open to ideas though) that shows how the p values change along the T dimension and the A/B dimension. I'd like to draw some kind of shape, or just have some type of indication, that specifically shows the region of p=X (for example, p=0.05). I want to make it obvious that anything touching or inside a given region is a p=X region.</p><p>I hope I articulated my question well. I've tried to generate this plot a few times now and it's surprisingly giving me a hard time. I guess I still need to get used to matlab more.</p><p>Any help would be appreciated.</p>Laith Alhusseinhttp://www.mathworks.com/matlabcentral/profile/authors/6688296-laith-alhusseintag:www.mathworks.com,2005:Question/2670002016-02-07T15:36:54Z2016-02-08T00:20:11ZDESIGNING AN ELMAN NET PROJECT<p>A MATLAB Central Contributor Question
Sent On:Feb 02/03/16 11:26 PM</p><p>Hi Greg,
I'm in a senior semester at university and our senior project is
about neural network by matlab and my mission is elman back propagation
neural network, but unfortunately, I don't know any thing about it.
can you help me please?</p><p>1. Start with the command line help and doc documentation</p><pre> lookfor elmannet
help elmannet
doc elmannet</pre><p>2. I am satisfied when</p><pre> a. the mean-square-error mse(target-output) is at least 100 times
smaller than the mean-target-variance mean(var(target',1))
b. the total number of weights net.numWeightElements is as small
as possible</pre><p>3. Run the help and doc examples</p><pre> a. Use defaults on 10 examples (Ntrials = 10, for i=1:Ntrials ...),
with different random initial weights </pre><pre> b. See if the number of hidden nodes can be reduced without
violating 2a</pre><pre> c. See if increasing the number of feedback delays makes a
significant difference</pre><p>3. For references search</p><pre> answers mathworks newsgroup </pre><pre> elman 22 26 51 </pre><pre> elman greg 11 11 16 </pre><p>4. Post an attempt on one or more of the other time-series example datasets
from</p><pre> help nndatasets
doc nndatasets </pre><pre> Hope this helps.</pre><pre> Greg</pre>Greg Heathhttp://www.mathworks.com/matlabcentral/profile/authors/2929937-greg-heathtag:www.mathworks.com,2005:Question/2670492016-02-08T00:11:16Z2016-02-08T00:11:16Zunable to activate R2015b on Mac Yosemite. <p>I have a license for matlab 2015b but when I activate with my mathwork account, I met connection problem and I try to fix the proxy, but the Great Firewall just block port 809(As the team said, the firewall needs to bypass blocked connections, TCP ports 80 and 443, for both of these addresses over both of these ports.) So how can I suppose to do?</p>LIAANGYI WEIhttp://www.mathworks.com/matlabcentral/profile/authors/7633735-liaangyi-weitag:www.mathworks.com,2005:Question/2670412016-02-07T22:20:15Z2016-02-08T00:10:57ZUsing ODE to solve a system of 19 equations. There seems to be something wrong with the system.<p>I am trying to solve a system of 19 differential equations. It is a chemical reaction problem, and each of the 19 equations represent the change in concentration of that species as a function of time, dC/dT.</p><p>When I use ODE45 to solve the system, I get unexpected results. The concentration of two of the components become abnormally high. Usually, high concentration of a component favors the reactions that consume the component. The current results are showing the two components that obtain abnormally high concentration. I don't think this should happen.</p><p>There is one thing I noticed, and I hope that you can explain. When I change the value of k1 to something absurdly large (i.e. 100000), the results do not change.</p><pre class="language-matlab">function Yv = runODE()
tic;
%Initialize concentrations.
initialvalues = [0.12;3.75;0;3.29;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0];
timespan = [0 400];
[tv,Yv]=ode45('funsys',timespan,initialvalues);
toc;
end
</pre><pre class="language-matlab">function Fv=funsys(t,Y)
% Initialize rate constants
k1 = 4;
k2 = 1;
k3 = 0.6;
k4 = 0.4;
k5 = 0.01;
k6 = 0.0008;
k7 = 0.001;
k8 = 0.002;
k9 = 0.0001;
k10 = 5;
k11 = 0.1;
k12 = 0.9;
k13 = 0.1;
k14 = 100;
k15 = 0.05;
k16 = 100;
k17 = 0.1;
k18 = 0.01;
k19 = 0.001;
k20 = 500;
k21 = 100;
k22 = 10;
k23 = 100;
</pre><pre class="language-matlab">Fv(1) = -k1*Y(1)*Y(2)+k2*Y(3)+k6*Y(6)*Y(4)+k8*Y(5)-k10*Y(1)^2+k11*Y(11)-k14*Y(12)*Y(1)-k16*Y(11)*Y(1)+k17*Y(16)+k24*Y(19)*Y(13);%%%
Fv(2) = -k1*Y(1)*Y(2)+k2*Y(3)-k4*Y(3)*Y(2)+k5*Y(6)-k15*Y(13)*Y(2)^2-k18*Y(15)*Y(2)^2-k19*Y(14)*Y(2);
Fv(3) = k1*Y(1)*Y(2)-k2*Y(3)-k3*Y(3)*Y(4)-k4*Y(3)*Y(2)+k5*Y(6)+k7*Y(5);
Fv(4) = -k3*Y(3)*Y(4)-k6*Y(6)*Y(4)+k7*Y(5)-k20*Y(18)*Y(4)+k21*Y(8)*Y(19);
Fv(5) = k3*Y(3)*Y(4)-k7*Y(5)-k8*Y(5)-k9*Y(5);
Fv(6) = k4*Y(3)*Y(2)-k5*Y(6)-k6*Y(6)*Y(4);
Fv(7) = k6*Y(6)*Y(4);
Fv(8) = k8*Y(5)+k20*Y(18)*Y(4)-k21*Y(8)*Y(19);
Fv(9) = k9*Y(5);
Fv(10) = k9*Y(5);
Fv(11) = k10*Y(1)^2-k11*Y(11)-k12*Y(11)+k13*Y(12)*Y(13)-k16*Y(11)*Y(1)+k17*Y(16)+k19*Y(14)*Y(2)-k22*Y(19)*Y(11)+k23*Y(14);
Fv(12) = k12*Y(11)-k13*Y(12)*Y(13)-k14*Y(12)*Y(1);
Fv(13) = k12*Y(11)-k13*Y(12)*Y(13)-k15*Y(13)*Y(2)^2-k24*Y(19)*Y(13);%%%
Fv(14) = k14*Y(12)*Y(1)-k19*Y(14)*Y(2)+k22*Y(19)*Y(11)-k23*Y(14);
Fv(15) = k15*Y(13)*Y(2)^2-k18*Y(15)*Y(2)^2;
Fv(16) = k16*Y(11)*Y(1)-k17*Y(16);
Fv(17) = k18*Y(15)*Y(2)^2;
Fv(18) = k19*Y(14)*Y(2)-k20*Y(18)*Y(4)+k21*Y(8)*Y(19);
Fv(19) = k20*Y(18)*Y(4)-k21*Y(8)*Y(19)-k22*Y(19)*Y(11)+k23*Y(14)-k24*Y(19)*Y(13);%%%
</pre><pre class="language-matlab">end
</pre>Phwey Gilhttp://www.mathworks.com/matlabcentral/profile/authors/3657133-phwey-giltag:www.mathworks.com,2005:Question/2669422016-02-07T02:12:27Z2016-02-07T23:50:56ZPlease help me with the code....<p>How to add space between each characters in matrix and those should be converted into ASCII...</p><p>For example taking string as input ie, matlabiseasy that has to be stored in matrix and remaining should be replaced with zeros as</p><pre class="language-matlab">m a t l
a b i s
e a s y
0 0 0 0
</pre><p>But when I execute this... there won't be space between 2 characters. ie,</p><pre class="language-matlab">matl
abis
easy
0000
</pre><p>As in C dont we have any fuction as /t for space... And how to convert the character to ASCII please help me with this code..</p>radhika s gowdahttp://www.mathworks.com/matlabcentral/profile/authors/7619788-radhika-s-gowdatag:www.mathworks.com,2005:Question/2664572016-02-03T15:21:02Z2016-02-07T23:21:05ZCode for Pig Dice game incorrect.<p>I've been working on this code for hours and cannot solve why it won't give the player a turn, save scores correctly, and just keeps playing for the computer. Rules for Pig: 1. Pig is a dice game played with 2 dice and any number of players. 2. The first player to reach a score of 100 wins. 3. Play begins with Player 1 making the first roll. At the end of each roll, the player can choose to hold (end his/her turn) or roll again. A player can roll as many times as he/she chooses and keeps a running total of the sum of the two dice. However, if the player rolls a 1, he/she loses all of the points for that particular turn.</p><p>The dice file is attached.</p><p>My code:</p><pre class="language-matlab">clear;
home;
load Dice;
players=input('How many players would you like?: ');
if players > 7;
fprintf('Pick a value between 2-7\n');
players=input('How many players would you like?: ');
else;
end;
valuetotal=[];
pname={};
compnames=['Tom','Mike','Susan','Joe','Billy','Evan','Sarah'];
for p=1:players;
p2=num2str(p);
test=strcat('What mode is player ', p2,' in?');
value=menu(test,' Player','Computer');
if value == 1;
pname(p)=cellstr(input('What is your name?','s'));
else;
pname(p)=cellstr('computer');
end;
valuetotal=[valuetotal,value];
end;
scores = zeros(1,players);
while scores(p) < 100;
if scores(p)>=100;
fprintf('Player',p,'wins!');
clc;
clear;
home;
end;
switch p;
case 1;
if value == 1;
again=1;
while again ==1;
figure('WindowStyle','docked');
roll = randi([1 6],[1 2]);
figure('WindowStyle','docked');
close;
imshow([Dice{roll}],'InitialMagnification','fit');
scores(p)=scores(p)+sum(roll);
if roll(1)==1 || roll(2)==1;
scores(p)=scores(p)-sum(roll);
again=2;
end;
again=menu('Would you like to roll again?','Yes','No');
end;
end;
case 2;
compchoice=1;
if value == 2;
while compchoice == 1;
figure('WindowStyle','docked');
roll = randi([1 6],[1 2]);
figure('WindowStyle','docked');
close;
imshow([Dice{roll}],'InitialMagnification','fit');
scores(p)=scores(p)+sum(roll);
if roll(1)==1 || roll(2)==1;
scores(p)=scores(p)-sum(roll);
compchoice=2;
end;
compchoice=randi(1,2);
end;
end;
end;
end
</pre>John Goodwinghttp://www.mathworks.com/matlabcentral/profile/authors/7614057-john-goodwingtag:www.mathworks.com,2005:Question/2670182016-02-07T18:40:48Z2016-02-07T23:15:14ZHow can you find circular blobs in an image?<p>I am trying to find certain parts of an image, and so used the Canny edge detector. Now I want to get rid of all the edges that are not vaguely circular in shape. How can I remove them?</p><p>This is a sample image that I am trying to search.</p><img src = "/matlabcentral/answers/uploaded_files/44914/Edges.PNG">AGhttp://www.mathworks.com/matlabcentral/profile/authors/7088606-agtag:www.mathworks.com,2005:Question/2670242016-02-07T19:26:28Z2016-02-07T23:12:58ZMath operations with Imported Data from Text<p>I have imported a text file. When I multiply the cells such as, filename(4,7)*filename(6,5); I get an error. I extracted data as cells since it includes both strings and the numbers. How can I handle this problem?</p>ferthttp://www.mathworks.com/matlabcentral/profile/authors/5087910-ferttag:www.mathworks.com,2005:Question/2669582016-02-07T06:11:24Z2016-02-07T23:05:20ZHow to use fminbnd correct Re: steepest descent method<p>I am trying to code a steepest descent problem. I have the main file:</p><p>I have edited my file and combined the two functions into one .</p><p>The objective function is "c". The variables in this problem are q, t and alpha. q and t appear in "c", while alpha appears in the re-expressed anonymous function based off "c" in the later part of the code.</p><p>I'm trying to minimize c using the steepest descent problem. First I find the gradient (partial differential equations of c with respect to q and t), then i use subs and double to generate new values of q and t with each iteration in the while loop. I also use fminbnd as a line search to find the value of the step size, "alpha" that minimizes the objective function during each iteration.</p><pre class="language-matlab">syms q t alpha
</pre><pre class="language-matlab">a = 0.20; %annual fixed charges, fraction
c_c = 12.50; %crude oil price, $/kL
c_i = 0.50; %insurance cost, $/kL
c_x = 0.90; %customs cost, $/kL
i = 0.10; %interest rate
n = 2; %number of ports
p = 7000; %land price, $/m2
</pre><pre class="language-matlab">c = c_c + c_i + c_x + ...
+ (2.09e4*t.^-0.3017) / 360 ...
+ (1.064e6*a*t.^0.4925) / (52.47*q*360) ...
+ (4.242e4*a*t^0.7952) / (52.47*q.*360) ...
+ (1.813*i*p*(n*t+1.2*q).^0.861) / (52.47*q*360) ...
+ 4.25e3*a*(n*t+1.2*q) / (52.47*q*360) ...
+ (5.024e3*q.^-0.1899)/360 + (0.1049*q.^0.671)/360;
</pre><pre class="language-matlab">k=0; % iteration counter start for outer loop
eps=1; %tolerance for outer loop
</pre><pre class="language-matlab">x=[150000;450000]; %initial starting point
</pre><pre class="language-matlab">dq=diff(c,q); %equation of partial differentiation of c wrt q
dt=diff(c,t); %equation of partial differentiation of c wrt t
</pre><pre class="language-matlab">alpha = 100000; %initial step size for outer loop
</pre><pre class="language-matlab">while eps>1e-10 & k<10000 %tolerance and number of iterations
</pre><pre class="language-matlab">eps=double(abs(subs(dq, [q,t], [x(1),x(2)]))+abs(subs(dt, [q,t], [x(1),x(2)])));
</pre><pre class="language-matlab">% I used subs & double to make the partial differentiation terms dq and dt
% scalar to calculate eps.
</pre><pre class="language-matlab">a1 = x(1) - alpha*double(subs(dq,[q,t],[x(1),x(2)]));
a2 = x(2) - alpha*double(subs(dt,[q,t],[x(1),x(2)]));
</pre><pre class="language-matlab">[alpha1,fval] = fminbnd(@(alpha) (c_c + c_i + c_x + ...
+ (2.09e4*(x(2)-alpha*double(subs(dt,[q,t],[x(1),x(2)]).^-0.3017) / 360 ...
+ (1.064e6*a*(x(2)-alpha*double(subs(dt,[q,t],[x(1),x(2)]).^0.4925) / (52.47*(x(1)-alpha*double(subs(dq,[q,t],[x(1),x(2)])*360) ...
+ (4.242e4*a*(x(2)-alpha*double(subs(dt,[q,t],[x(1),x(2)])^0.7952) / (52.47*(x(1)-alpha*double(subs(dq,[q,t],[x(1),x(2)]).*360) ...
+ (1.813*i*p*(n*(x(2)-alpha*double(subs(dt,[q,t],[x(1),x(2)])+1.2*(x(1)-alpha*double(subs(dq,[q,t],[x(1),x(2)])).^0.861) / (52.47*(x(1)-alpha*double(subs(dq,[q,t],[x(1),x(2)])*360) ...
+ 4.25e3*a*(n*(x(2)-alpha*double(subs(dt,[q,t],[x(1),x(2)])+1.2*(x(1)-alpha*double(subs(dq,[q,t],[x(1),x(2)])) / (52.47*(x(1)-alpha*double(subs(dq,[q,t],[x(1),x(2)])*360) ...
+ (5.024e3*(x(1)-alpha*double(subs(dq,[q,t],[x(1),x(2)]).^-0.1899)/360 + (0.1049*(x(1)-alpha*double(subs(dq,[q,t],[x(1),x(2)]).^0.671)/360))))))))))))))))))))))))))),10,120000)
</pre><pre class="language-matlab">alpha = alpha1;
</pre><pre class="language-matlab">x(1)=a1;
x(2)=a2;
</pre><pre class="language-matlab">x
</pre><pre class="language-matlab">k=k+1;
</pre><pre class="language-matlab">end
</pre><p>The problem is that I can get the code working, but the values of q, t and alpha are changing extremely slowly in each iteration.</p><p>I'm also having problems with "alpha" - in theory, "alpha" is supposed to change with each iteration, however my alpha value always takes on the maximum value (upper bound) in fminbnd and remains stationary.</p><p>If I remove this portion of the code:</p><pre class="language-matlab">[alpha1,fval] = fminbnd(@(alpha) (c_c + c_i + c_x + ...
+ (2.09e4*(x(2)-alpha*double(subs(dt,[q,t],[x(1),x(2)]).^-0.3017) / 360 ...
+ (1.064e6*a*(x(2)-alpha*double(subs(dt,[q,t],[x(1),x(2)]).^0.4925) / (52.47*(x(1)-alpha*double(subs(dq,[q,t],[x(1),x(2)])*360) ...
+ (4.242e4*a*(x(2)-alpha*double(subs(dt,[q,t],[x(1),x(2)])^0.7952) / (52.47*(x(1)-alpha*double(subs(dq,[q,t],[x(1),x(2)]).*360) ...
+ (1.813*i*p*(n*(x(2)-alpha*double(subs(dt,[q,t],[x(1),x(2)])+1.2*(x(1)-alpha*double(subs(dq,[q,t],[x(1),x(2)])).^0.861) / (52.47*(x(1)-alpha*double(subs(dq,[q,t],[x(1),x(2)])*360) ...
+ 4.25e3*a*(n*(x(2)-alpha*double(subs(dt,[q,t],[x(1),x(2)])+1.2*(x(1)-alpha*double(subs(dq,[q,t],[x(1),x(2)])) / (52.47*(x(1)-alpha*double(subs(dq,[q,t],[x(1),x(2)])*360) ...
+ (5.024e3*(x(1)-alpha*double(subs(dq,[q,t],[x(1),x(2)]).^-0.1899)/360 + (0.1049*(x(1)-alpha*double(subs(dq,[q,t],[x(1),x(2)]).^0.671)/360))))))))))))))))))))))))))),10,120000)
alpha = alpha1;
</pre><p>The convergence rate increases greatly. Any idea as to what may be causing this issue?</p>Jimhttp://www.mathworks.com/matlabcentral/profile/authors/7631110-jimtag:www.mathworks.com,2005:Question/2670422016-02-07T22:21:33Z2016-02-07T22:57:06Zhow can i debug this error for my code ?? Error using ==> plot Data may not have more than 2 dimensions<p>hi friends, i am trying to run this code each time, i am getting error like ??? Error using ==> plot Data may not have more than 2 dimensions please help me to debug this error.</p><pre class="language-matlab">subplot(2,2,1)
p=plot(k,Tot_Fairness_out,'-',k,average_Tot_fairness_out,'m-o');
% fairness for outer loop
set(p, 'LineWidth',2.5)
ylabel('LBE1+LBE2')
title('Jain`s total fairness index/10runs')
xlabel('(a) Number of runs')
legend('Index', 'Average (10 runs)')%
grid on
subplot(2,2,2)
p= plot(q,FI, '-+', q,Tot_Fairness_inner, 'g-^' );
set(p, 'LineWidth',2.5)
xlim([3 33])
title({'Jain`s fairness index/10 competitions'})
ylabel('LBE1+LBE2')
xlabel(' (b) q1 values for LBE-UE1')
legend('FI', 'Average (10 comp.)')
grid on
</pre>Zahra22http://www.mathworks.com/matlabcentral/profile/authors/2791832-zahra22tag:www.mathworks.com,2005:Question/2670192016-02-07T18:41:14Z2016-02-07T22:54:46ZHow to plot with pcolor one 2D function with two x axis ? <p>I would like to plot one function with two x axis.
One on the bottom one on the top. The top is just different vector. How to add the second x axis on the top ?</p><pre class="language-matlab">X = rand(100,100);
x = linspace(1,100,100);
x2 = linspace(0.1,1,100);
y = linspace(100,200,100);
pcolor(x,y,X);
</pre>Olehttp://www.mathworks.com/matlabcentral/profile/authors/5968107-oletag:www.mathworks.com,2005:Question/2670432016-02-07T22:27:41Z2016-02-07T22:54:37ZHI,how to add NURBS toolbox in matlab,?<p>HI,how to add NURBS toolbox in matlab,?</p>amina lkhttp://www.mathworks.com/matlabcentral/profile/authors/5411304-amina-lktag:www.mathworks.com,2005:Question/2670442016-02-07T22:29:57Z2016-02-07T22:53:28ZIn a set of data that I am trying to find the mean and std of, how can I input multiple copies of the same number?<p>Hello, I have a project in which I am studying a set of data consisting of about 4000+ numbers. I must find the mean and standard deviation of these numbers. All of the numbers in the set have multiple copies of each other, such as 1.74336 showing up in the data set 500+ times. Is there a code that can basically duplicate numbers in a data set a certain amount of times? I have the student edition of matlab 2014 so I would need a code that doesn't need any of the non-included toolboxes. Thank you so much for any help! I have included a sample of the data set as an attachment where the left side is the data and the right column is the number of occurrences.</p>steven schweigerhttp://www.mathworks.com/matlabcentral/profile/authors/7244495-steven-schweigertag:www.mathworks.com,2005:Question/2670172016-02-07T18:30:10Z2016-02-07T22:50:04ZHow do you call a function from another m.file?<p>I am trying to use another function's values to make a plot of error for a mathematical method. Here's my code so far. "Actualplot" is the name of a function that has the actual plot of an equation while "hw3question1a"is a function that used Euler's method to graph an equation. I'm not sure how to call the functions so that I can get their values for the error.</p><pre class="language-matlab">function[err]= errorcalc(x,e)
x=actualplot;
e=hw3question1a
t=0:50;
</pre><pre class="language-matlab">err=abs(x-e)/x;
plot(t,err);
xlabel('t') % Labels ??x?? axis
ylabel('Error') % Labels ??y?? axis
title('Error using Euler Method');
</pre>Mohannad Abboushihttp://www.mathworks.com/matlabcentral/profile/authors/7483240-mohannad-abboushitag:www.mathworks.com,2005:Question/2670402016-02-07T22:15:41Z2016-02-07T22:48:30ZHow to filter only numerical in a table?<p>I have data organized in a column in a <b>table</b> like this:</p><pre class="language-matlab">'1966.csv'
'1967.csv'
'1968.csv'
'1969.csv'
'1970.csv'
'1971.csv'
'1972.csv'
'1973.csv'
'1974.csv'
'1975.csv'
</pre><p>How could I only extract the numerical values (1966, 1967...) and organize them in a column beside the existing one?</p>Pablo Jaramillo Restrepohttp://www.mathworks.com/matlabcentral/profile/authors/3584039-pablo-jaramillo-restrepotag:www.mathworks.com,2005:Question/2670272016-02-07T19:50:56Z2016-02-07T22:41:08ZIs there a way of finding how much light gets projected onto face of a patch?<p>Hi,</p><p>Is there a way of finding how much light/intensity gets projected onto a face of a patch?</p><p>I am attempting to plot a surface, then convert each surface into a patch. I am introducing a light source at a certain position. Based on the plots, the faces exposed to light change color, while the faces that are not exposed to light get shaded. I am trying to find how much light/intensity each face gets from the source.</p><p>I have tried the code below. It seems that based on the colormap of each face, each face gets light equally, which doesn't seem to be the case when looking at the plots. Is there a way of finding how much light/intensity gets projected onto each face of a patch based on the location of the lighting?</p><pre class="language-matlab">[x,y,z]= cylinder([1 1],40);
</pre><pre class="language-matlab">cylinder1=surf(x,y,z);
</pre><pre class="language-matlab">surf_info = findall(cylinder1,'Type','surface');
</pre><pre class="language-matlab">fv = surf2patch(surf_info.XData,surf_info.YData,surf_info.ZData,surf_info.CData);
</pre><pre class="language-matlab">patch(fv,'FaceVertexCData',fv.facevertexcdata,'FaceColor','flat');
</pre><pre class="language-matlab">light1=light('Position',[2 2 2],'Style','local');
</pre><pre class="language-matlab">lighting flat
</pre><pre class="language-matlab">color_per_face = fvcdata(fv.faces(:,1));
</pre><pre class="language-matlab">color_map = colormap;
</pre><pre class="language-matlab">figure,plot(color_map)
</pre><pre class="language-matlab">color_per_face_2= fvcdata(fv.faces(:,2));
</pre><pre class="language-matlab">color_map_2 = colormap;
</pre><pre class="language-matlab">figure,plot(color_map_2)
</pre>Emminhttp://www.mathworks.com/matlabcentral/profile/authors/1501130-emmintag:www.mathworks.com,2005:Question/2670462016-02-07T22:36:48Z2016-02-07T22:36:48ZGenerating an ROC curve from 2 overlapping Gaussian/ Normal distribution curves?<p>Hello, I need to first generate 2 Normal/Gaussian distribution curves and then somehow create an ROC curve from that plot of the two curves. I have tried "erf" and "erfc" which didn't work as well as "randn" to generate some random values but nothing creates the shape that I need. Also, I have the student version so codes like "perfcurve" do not work on my program. Please, any help in the generation of these two plots would be great. I don't even know what codes to begin with. I have included a .jpg of what i essentially have to create through matlab.</p>steven schweigerhttp://www.mathworks.com/matlabcentral/profile/authors/7244495-steven-schweigertag:www.mathworks.com,2005:Question/2670452016-02-07T22:35:27Z2016-02-07T22:42:42ZWhy is spmd with two workers on a single core faster than on 2 cores<p>Hi,</p><p>I know the questions has already been asked several times and I've read the answers but none of them really addresses the following problem:</p><p>I've set in all cases maxNumCompThreads to one. I'm using 'taskset -c 3' for single core computation and 'taskset -c 2,3' for two cores when starting Matlab on linux. All computations are run on my laptop. I set matlabpool(2);</p><p>Computing</p><pre class="language-matlab">spmd
B=rand(4000,4000);
c=inv(B);
</pre><pre class="language-matlab">end
</pre><p>(is of no use but just to get a very simple instance of the problem)
with a single cpu core takes the same time as with 2... (about 13 sec) and I can indeed see that in the first case only one core is working and it's at 100% and in the second only 2 cores are working and they're both at 100%.</p><p>I don't have any clue why it's not at least somewhat faster... In any case a for loop on even a single core outperforms spmd... 11sec</p><p>I've made sure Matlab is not simply computing things once because they lead to the same result.</p><p>Thank you for your help!</p>Alexandre Halbachhttp://www.mathworks.com/matlabcentral/profile/authors/1693188-alexandre-halbachtag:www.mathworks.com,2005:Question/2670252016-02-07T19:47:48Z2016-02-07T22:33:51ZHow can I use a variable (i.e. a folder path) as the argument for cd function?<p>Hi! I think this is a syntax-type question:</p><p>I want to use cd to change between directories that are stored in a looping variable. What would be the syntax so <b>cd('path');</b> can be performed, 'path' being :\Users\p_jarami\A\'</p>Pablo Jaramillo Restrepohttp://www.mathworks.com/matlabcentral/profile/authors/3584039-pablo-jaramillo-restrepotag:www.mathworks.com,2005:Question/2669822016-02-07T11:23:02Z2016-02-07T22:27:32ZCount the 'duration' of integer values appearing sequentially in a list (viterbi path)<p>I have a long (~250 000) sequence of integers between 1 and 10 which represent a sequence of states (viterbi path) which is the output of a hidden markov model.</p><p>I would like to get the durations of each individual state and put these into a matrix (or perhaps several vectors as they may have different lengths, I'm not sure how to deal with this).</p><p>an example vpath might be [1 1 1 2 2 3 3 2 2 1 1 1 1 1 4 4 4] and I would like to return something like so</p><pre class="language-matlab">3 5 ##first and second durations of state 1
2 2 ## first and second durations of state 2 etc.
2
3
</pre><p>Here is the code I have so far (the appraoch is really ugly and gives me weird numbers at the beggining and end, sorry that you have to look at it):</p><pre class="language-matlab">%should return array of length K with ave. number of samples per state visit
function visits = state_duration(vpath, K)
visits = [];
</pre><pre class="language-matlab">a = zeros(length(vpath), K);
b = ones(K,1);
visits.avgs = zeros(K,1);
</pre><pre class="language-matlab">for x = 1:K
for i = 1:length(vpath)
if vpath(i)==x
a(b,x)=a(b,x)+1;
else
b(x)=(b(x)+1);
end
end
rws = a(2:end,x);
visits.avgs(x)=mean(rws(rws~=0));
end
visits.full = a(2:end,:);
end
</pre><p>**if anyone can think of a better way to phrase this question let me know</p>Alexander Morleyhttp://www.mathworks.com/matlabcentral/profile/authors/7631669-alexander-morleytag:www.mathworks.com,2005:Question/2670322016-02-07T20:44:41Z2016-02-07T22:20:22ZHow to convert a GUI to an .exe application?<p>Hi, I want to make my GUI a standalone application.</p>Mr. BOUREZGhttp://www.mathworks.com/matlabcentral/profile/authors/2833188-mr-bourezgtag:www.mathworks.com,2005:Question/2670222016-02-07T19:22:55Z2016-02-07T22:19:45ZWhat setting and starting point should I use for FMINCON, matlab<p>Currently I have a very simple function that should be minimized subject to some constraints. I am wonder, how can I correctly tune the fmincon settings to get the best minimum with exit Flag 1. This settings will give me exit flag of -2.
Here is my Matlab code:</p><pre class="language-matlab">%% Main
lb=[-1e5,-1e5,0];
ub=[1e5,1e5,1e5];
x0 = unifrnd (lb,ub,[1,3]);
options=optimset('display','off','algorithm','sqp');
[x,~,exitflag]=fmincon(@myfun,x0,[],[],[],[],lb,ub,@mycons,options);
disp(['Exit Flag: ', num2str(exitflag)])
%---------------------------
</pre><pre class="language-matlab">function f=myfun(x)
f=x(2)-4*x(3)^2;
end
%---------------------------
</pre><pre class="language-matlab">function [c,ceq]=mycons(x)
x1=x(1); x2=x(2); x3=x(3);
N= [20 1]; xp=[12 0.4];
c(1)=((x1-20)/20)^8+((x2-1)/1)^8-1;
ceq(1)=([1,-1]*(([x1 x2]-xp)./N)')+x3.^2;
end
</pre>Jamais avenirhttp://www.mathworks.com/matlabcentral/profile/authors/4439075-jamais-avenirtag:www.mathworks.com,2005:Question/2670282016-02-07T19:56:48Z2016-02-07T22:15:48ZHow can I write a function that reduces image's size? I need help with how to pass in the image and then work with it. <p>For instance if this is the format, how can I load the image in 'image' ? Do we do it it command window.</p><p>function sampledimage = subsample(image,factor)</p>tehreem fatimahttp://www.mathworks.com/matlabcentral/profile/authors/7557199-tehreem-fatimatag:www.mathworks.com,2005:Question/2670202016-02-07T18:55:04Z2016-02-07T22:15:32ZHow to redefine indices of a vector?<p>I am trying to call the max value of a vector, and the index it occurs at. For a small example, lets say I have:</p><p>A = [3;6;7;2;0]</p><p>[MAXval,i] = max(A)</p><p>This will result in MAXval having a value of 7. The resulting index, i, is 3 because the max value (7) occurs in the third row of the matrix.</p><p>However, what I am doing is creating vectors involving time. Each increment of the vector occurs at, for example, .25 second increments. So in reality the max value does not occur at 3 seconds, but at .75. So I want to be able to get a resultant i value of .75 when I ask for the max value index.</p><p>This is just a simple example, and what I'm doing is more complicated. The time increments are .1, and I'm using nested for loops in combination with a second order equation, so my values are all over the place.</p><p>So my question is, is there a way to edit the incremental values of a vector?</p>ATMLVEhttp://www.mathworks.com/matlabcentral/profile/authors/7632884-atmlvetag:www.mathworks.com,2005:Question/2670392016-02-07T22:14:31Z2016-02-07T22:14:31ZHow to describe and plot spatial continuation of a plane figure?<p>I have a projection binary image of arbitrary shape. I want to continue the shape, the projection into the 3rd dimension by arbitrary length, store it and 3d-plot it.
What are: the way of building such a spatial object out of any plane base, the way of describing it and then plotting?</p>Anton Grubahttp://www.mathworks.com/matlabcentral/profile/authors/7121323-anton-grubatag:www.mathworks.com,2005:Question/2670382016-02-07T22:07:02Z2016-02-07T22:11:31ZReading time and dates from Excel<p>Hey guys,</p><p>I have a problem using the xlsread function, in my spreadsheet,my dates are given in the following format:</p><img src = "/matlabcentral/answers/uploaded_files/44916/%E6%90%9C%E7%8B%97%E6%88%AA%E5%9B%BE16%E5%B9%B402%E6%9C%8807%E6%97%A51704_1.png"><p>So i used [numericData, stringData, allData] = xlsread(dataSource);
But all the dates are in the string data is there a way that i can get those dates into the numericData?</p>fengwei jinhttp://www.mathworks.com/matlabcentral/profile/authors/6206473-fengwei-jintag:www.mathworks.com,2005:Question/2670112016-02-07T17:21:28Z2016-02-07T22:08:33ZDrawing line from center to other three points<p>I want to know if its possible to draw lines from a vector which has two points and is the central point to another vector that has 3 points. Bassically, it like drawing a line from center to three points. I am using Matlab.</p>BlueBee77http://www.mathworks.com/matlabcentral/profile/authors/3335062-bluebee77tag:www.mathworks.com,2005:Question/2670312016-02-07T20:39:16Z2016-02-07T22:08:05Zlabeling points on graph<p>I have this script:</p><p>n = [10e21,10e18,10e27,10e36,10e32];
kt = [10000, 10, 1000, 10, 10^5];
loglog(kt,n,'go')</p><p>How can I label each point on my graph with a unique string value?</p><p>I want to add the text, "Reactor" at the first point, and add another word to the second pt etc.</p><p>How can I do this?</p>Benjamin Cowenhttp://www.mathworks.com/matlabcentral/profile/authors/4307929-benjamin-cowentag:www.mathworks.com,2005:Question/2670292016-02-07T20:00:43Z2016-02-07T22:07:31ZHi, I am having a hard time finding the root to a polynomial function using the bisection method <p>Hi,</p><p>I am having a hard time finding the root to a polynomial function using the bisection method with the precision of 0.001. This is not a homework question. I am new at this and just trying to learn. This is what I have, but I have errors. I do appreciate any help or advice.</p><pre class="language-matlab">function root[x_lower,x_upper] 3*x.^3-10;
x_lower=-5;
x_upper=5;
x_mid= (x_lower* X_upper)/2;
while abs (f(x_mid))>0.001
if (f(x_mid)*f(x_upper))<0
x_lower=x_mid
else
x_upper=x_mid
end
x_mid=(x_lower+x_upper)/2;
end
fprintf('the root is %g\n', x_mid)
</pre>Nasser Yarihttp://www.mathworks.com/matlabcentral/profile/authors/7392961-nasser-yaritag:www.mathworks.com,2005:Question/2670342016-02-07T21:22:24Z2016-02-07T22:05:12Znot formed from a valid identifier; using the end function for a simple m file.<p>I am essentially copying the exact same code my prof used on powerpoint and yet the code keeps telling me this doesnt work. No matter what I put for the last line an error says " is not formed from a valid matlab identifier.</p><pre class="language-matlab">a=e^2
if a<x
disp ('a is less than x');
elseif a>x
disp ('a is greater than x');
end
</pre><p>[EDITED, Jan, code formatted]</p>Kyle Grayhttp://www.mathworks.com/matlabcentral/profile/authors/7492762-kyle-graytag:www.mathworks.com,2005:Question/2670372016-02-07T22:00:39Z2016-02-07T22:38:40ZQuestion about Covariance matrix from 'SPA' function<p>Hello MATLAB geniuses,</p><p>So when one identifies the frequency response of a system using the SPA function, we can obtain the covariance matrix. Suppose I have an input 'u' and output 'y' of an experiment, with 'Ts' being the sampling time, 'winSize' being the window size of the identification, and 'freq' being the vector of frequency points to use in obtaining the frequency response. Then the covariance matrix can be obtained as follows:</p><pre class="language-matlab">dat = iddata(y,u,Ts)
G = spa(data,winSize,freq)
Covariance_Matrix = squeeze(G.CovarianceData)
</pre><p>For my case, the covariance matrix (at each frequency) is a 2x2 matrix, where Covariance_Matrix(k,1,1) is the variance in the real part, and Covariance_Matrix(k,2,2) is the variance in the imaginary part (for any positive integer k). My question is, how exactly are these values calculated? Do these values depend on the output noise spectrum? Basically, if I wanted to calculate this covariance matrix myself, how would I do it? The documentation, unfortunately, does not seem to mention anything about this.</p><p>Your help is much appreciated!</p><p>-Achille</p>Achille Nicolettihttp://www.mathworks.com/matlabcentral/profile/authors/5434679-achille-nicolettitag:www.mathworks.com,2005:Question/2670362016-02-07T21:50:07Z2016-02-07T21:50:07Zwhy is my PI controller having no output when it has inputs?<p>i have a model in simulink power system of R2013a but when i run the simulation, the PI controller does not give an output. i have checked and its inputs are ok. i have tried different solvers with no change but when i change the time domain of the controller from discrete to continuous time, it gives this error message</p><p>"Derivative input 15 of 'wind_and_gen/powergui/EquivalentModel1/State-Space' at time 0.0 is Inf or NaN. Stopping simulation. There may be a singularity in the solution. If not, try reducing the step size (either by reducing the fixed step size or by tightening the error tolerances)"</p><p>please can anybody help out with how to check/solve singularity or what to do with the pi controller in discrete time domain to give an output?</p>tochukwu victorhttp://www.mathworks.com/matlabcentral/profile/authors/6600285-tochukwu-victortag:www.mathworks.com,2005:Question/2670332016-02-07T21:00:25Z2016-02-07T21:43:11Zhow do i make the size of the strings appear bigger in plot<pre class="language-matlab">n = [10e21,10e18,10e27,10e36,10e32];
kt = [10000, 10, 1000, 10, 10^5];
loglog(kt,n,'go')
strings = {' reactor', ' point 1',' point 2',' point3',' point4'}
for ind = 1:length(n)
text(kt(ind),n(ind),strings{ind})
end
</pre>Benjamin Cowenhttp://www.mathworks.com/matlabcentral/profile/authors/4307929-benjamin-cowentag:www.mathworks.com,2005:Question/2670132016-02-07T17:34:45Z2016-02-07T21:21:27ZHighlight some parts of text file <p>Hello,I have a text file and I want to highlight some parts of it using matlab codes.But i do not have any idea how to do it. Can anyone help me?thanks</p>Fateme Jalalihttp://www.mathworks.com/matlabcentral/profile/authors/7292066-fateme-jalalitag:www.mathworks.com,2005:Question/2670302016-02-07T20:34:16Z2016-02-07T20:45:37ZHow can i get U as 5 answers in a column?<p>n = [0.035 0.020 0.015 0.030 0.022];</p><p>S = [0.0001 0.0002 0.0010 0.0007 0.0003];</p><p>B = [10 8 20 24 15];</p><p>H = [2 1 1.5 3 2.5];</p><p>U = ((sqrt(S))/n) .* ((B.*H)/(B+2*H))^(2/3);</p><p>disp(U)</p>Volker Kresserhttp://www.mathworks.com/matlabcentral/profile/authors/7223355-volker-kressertag:www.mathworks.com,2005:Question/2670212016-02-07T19:22:45Z2016-02-07T20:09:23ZHow can I run a previously used function using a pushbutton?<p>So I'm writing a code that will ask a user to input a matrix. It will then show them the matrix in a table, and ask them if it is correct. There will be a 'Yes' and a 'No' button. If they click the 'Yes' button, it will simply close the program. If they click the 'No' button, I would like it to go back and run the original function again, which asks them to input a matrix. I'm very confused, as I can't seem to figure out how you're supposed to do this, but it feels like this should be fairly easy...
How can I make a pushbutton initiate a function which has already been used, without rewriting the entire function again? I can include my entire code if necesary, but it is rather lengthy, and all of it works properly except for the 'No' button. Basically my question comes down to this:
Assuming that I write a rather lengthy function:</p><pre class="language-matlab">function matrix_input %Generate the actual window prompt
~ ~ ~ ~ ~ Lots of stuff going on in here including creating a window to input the matrix, and a 'submit' button
~ ~ ~ ~ ~
end
</pre><p>Which then opens up a second gui which displays the matrix and has the 'yes' and 'no' buttons:</p><pre class="language-matlab">function submitbtn_Callback
~ ~ ~ ~ Lots of stuff going on in here, including the creation of a 'matrixdisplay' window which has the two buttons on it
~ ~ ~ ~
end
</pre><p>How can I, later on, call back this function without needing to rewrite it all? I don't have any idea how to write this, but my best guess was something like this:</p><pre class="language-matlab">function nobtn_Callback(~, ~, matrixdisplay)
function matrix_input
end
end
</pre><p>In English, it'd be something like:</p><p>When nobtn is pressed, go to the function 'matrix_input' and do it again</p><p>I'm super lost, I feel like this should be relatively easy, so any help would be greatly appreciated!</p>Chris Gnamhttp://www.mathworks.com/matlabcentral/profile/authors/7586965-chris-gnamtag:www.mathworks.com,2005:Question/2670152016-02-07T18:15:02Z2016-02-07T20:07:19Zsetting up a random vector that sums up to 1.<p>How can I set up a random vector that will sum up to 1.</p>A123456http://www.mathworks.com/matlabcentral/profile/authors/6168237-a123456tag:www.mathworks.com,2005:Question/2624512016-01-02T20:57:38Z2016-02-07T20:05:40Zin a code of encryption if y=mod(x,256); is used. how can i apply the same statement in decryption process to get x back if i have only y and 256 know..<p>encryption scheme i used was bit level permutation</p>tania http://www.mathworks.com/matlabcentral/profile/authors/6927129-taniatag:www.mathworks.com,2005:Question/2668202016-02-05T16:44:19Z2016-02-07T20:05:27ZHow to create monthly average from daily data?<p>Hi Everybody;</p><p>I have used daily data for 34 years, I have one row and 11690 columns, by the way I have some missing data in 1994 (the last three months) and 2000 (I have only last tow months). I would like to make monthly average and then for Normal year and Leap year.</p><p>Thank you in advance.</p>reyadh Albarakathttp://www.mathworks.com/matlabcentral/profile/authors/6292760-reyadh-albarakattag:www.mathworks.com,2005:Question/2670262016-02-07T19:47:51Z2016-02-07T19:47:51ZThe ques is to plot the equation on z-plane: x(n)=-a^n*u(-n-1). But in my code,the ROC is plotting outside the circle which should be inside the circle actually. And the stem of the equation should be start from 0 to - scale .Whats's wrong in code?<p>clear all;
close all;
clc;
n=-10:-1;
a=2;
y =-a.^n.*heaviside(-n-1);
figure(1)
zplane(y)
figure(2)
stem(y)</p><p>function:function y = heaviside(n)
% We assume a vector input</p><p>% Our default output value is 0
y = 0 * n;
% Now, we find values in n greater than or equal to 0
y(find(n >= 0)) = 1;</p>farah pianihttp://www.mathworks.com/matlabcentral/profile/authors/6613159-farah-pianitag:www.mathworks.com,2005:Question/2378182015-08-29T21:35:03Z2016-02-07T19:41:26Zheadless install of matlab<p>I'd like install matlab 'noninteractively' in a docker container so that we can deploy our stack (which includes matlab calculations) painlessly.
I've seen that people do this by wget of the install file - but I can't find a working url of the install file. Has anyone done this with R2015a?</p>Jeremy Rutmanhttp://www.mathworks.com/matlabcentral/profile/authors/5476872-jeremy-rutman