https://www.mathworks.com/matlabcentral/newsreader/most_recent_feed
MATLAB Central Newsreader Recent Posts
Most Recent Posts
enus
©19942017 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
https://www.mathworks.com/images/membrane_icon.gif

Tue, 23 May 2017 19:04:29 +0000
Re: calling GA from command line in matfile
https://www.mathworks.com/matlabcentral/newsreader/view_thread/348609#954179
Alan Weiss
On 5/23/2017 2:47 AM, roshani thapa wrote:<br>
> I am using GA for my optimisation work, calling GA function from a mat<br>
> file. How do i save the population data to the workspace and start<br>
> optimisation later from the same saved point.<br>
<br>
It is difficult to start from exactly where you left off, but you can <br>
call ga using the syntax<br>
<br>
[x,fval,exitflag,output,population] = ga(...)<br>
<br>
To restart more or less where you left off, set the ga <br>
InitialPopulationMatrix option to the population output. Or, for older <br>
MATLAB versions, call this the InitialPopulation option.<br>
<br>
The reason I say more or less is that the ga algorithm has a different <br>
state, so it won't exactly be the same as running ga longer, but at <br>
least it will start from the population it ended with.<br>
<br>
Alan Weiss<br>
MATLAB mathematical toolbox documentation

Tue, 23 May 2017 18:23:03 +0000
Re: Plotting Bounding Box in a Video
https://www.mathworks.com/matlabcentral/newsreader/view_thread/310846#954178
Tarun Uday
@suhas<br>
<br>
They've gone into separate lines, put those two lines into a single line:<br>
<br>
newWindowPosition = [1 screenSize(4)/2  70 screenSize(3) screenSize(4)/2];

Tue, 23 May 2017 18:20:35 +0000
Re: Inequalities with if statements
https://www.mathworks.com/matlabcentral/newsreader/view_thread/348616#954177
dpb
On 05/23/2017 11:46 AM, Fatih Caglayan wrote:<br>
...<br>
<br>
> if (0<X<=0.3)<br>
...<br>
<br>
To amplify on other response that shows what happens, it's as if wrote<br>
<br>
flg=(0<X) <= 0.3;<br>
if flg<br>
...<br>
<br>
So, the result will always be T if 0<X is False or X<=0 since result of <br>
the first conditional is always either 01<br>
<br>
IOW, the combined expression reduces to<br>
<br>
if X<=0<br>
...<br>
<br>


Tue, 23 May 2017 18:13:03 +0000
Re: Inequalities with if statements
https://www.mathworks.com/matlabcentral/newsreader/view_thread/348616#954176
Saravanan Mani
"Fatih Caglayan" wrote in message <og1p0b$8ul$1@newscl01ah.mathworks.com>...<br>
> Hello, it is known that in Matlab the following piece of code will not work as in other programming languages:<br>
> <br>
> X = 0.2;<br>
> if (0<X<=0.3)<br>
> disp('true');<br>
> else<br>
> disp('false');<br>
> end<br>
> <br>
> You should program the following instead in Matlab:<br>
> <br>
> X = 0.2;<br>
> if (0<X && X <=0.3)<br>
> disp('true');<br>
> else<br>
> disp('false');<br>
> end<br>
> <br>
> However, I got curious to what Matlab is actually checking in the first above. I used to think that "0<X<=0.3" meant larger than 0 OR smallerequal 3, so I though that it would be always true, no matter what, but this doesn't seem to be the case. It also not either one of those. So I was wondering whether someone knows what is actually happening in the background when someone executes the first example.<br>
<br>
Dear Fatih,<br>
<br>
Good Question.<br>
<br>
Most of the operator is work from left to right, May be you can go through matlab help for "operator precedence". you will get to know more information.<br>
<br>
In this case the first(top above) one how it will work, i will explain you. <br>
<br>
Let's take our logic : X = 0.2, (0<X<=0.3), so first matlab will calculate 0<0.2 = 1, then 1<=0.3 = 0, so what is the answer will display "false".<br>
<br>
I can place here matlab command window calculation.<br>
<br>
>> X = 0.2;<br>
>> 0<X<br>
<br>
ans =<br>
<br>
1<br>
<br>
>> 1<=0.3<br>
<br>
ans =<br>
<br>
0<br>
<br>
I hope you are understand the logic<br>
<br>
Thanks & Regards,<br>
Saravanan

Tue, 23 May 2017 17:54:27 +0000
Re: Inequalities with if statements
https://www.mathworks.com/matlabcentral/newsreader/view_thread/348616#954175
dpb
On 05/23/2017 11:46 AM, Fatih Caglayan wrote:<br>
> X = 0.2;<br>
> if (0<X<=0.3)<br>
...<br>
><br>
> However, I got curious to what Matlab is actually checking in the first above.<br>
...<br>
<br>
Simple enough. It's two expressions evaluated serially LtoR.<br>
<br>
Easily demonstrated:<br>
<br>
>> 0<X, ans<=0.3<br>
ans =<br>
1<br>
ans =<br>
0<br>
>><br>
<br>
>> X=0;<br>
>> 0<X, ans<=0.3<br>
ans =<br>
0<br>
ans =<br>
1<br>
>><br>
<br>


Tue, 23 May 2017 16:46:03 +0000
Inequalities with if statements
https://www.mathworks.com/matlabcentral/newsreader/view_thread/348616#954174
Fatih Caglayan
Hello, it is known that in Matlab the following piece of code will not work as in other programming languages:<br>
<br>
X = 0.2;<br>
if (0<X<=0.3)<br>
disp('true');<br>
else<br>
disp('false');<br>
end<br>
<br>
You should program the following instead in Matlab:<br>
<br>
X = 0.2;<br>
if (0<X && X <=0.3)<br>
disp('true');<br>
else<br>
disp('false');<br>
end<br>
<br>
However, I got curious to what Matlab is actually checking in the first above. I used to think that "0<X<=0.3" meant larger than 0 OR smallerequal 3, so I though that it would be always true, no matter what, but this doesn't seem to be the case. It also not either one of those. So I was wondering whether someone knows what is actually happening in the background when someone executes the first example.

Tue, 23 May 2017 16:03:03 +0000
How to make realtime animation of aircraft trajectory during flight in Matlab Simulink?
https://www.mathworks.com/matlabcentral/newsreader/view_thread/348615#954173
tag
I have a flying aircraft in Matlab. I want to make animation of its trajectory during flight like it is leaving trace behind. I tried to use animatedline function if Matlab, but I'm just stuck here. My function just displays only ?oordinate axes and nothing more.<br>
This function should draw trajectory in realtime during simulation.<br>
Coordinates of aircraft are entering during flight from Simulink model. Please, help me!<br>
<br>
function trajectory(uu)<br>
pn = uu(1); % inertial North position<br>
pe = uu(2); % inertial East position<br>
pd = uu(3); % inertial Down position<br>
t = uu(4); % time<br>
<br>
if t==0,<br>
figure(10), clf<br>
S = 1500;<br>
view(0,90)<br>
axis([S,S,S,S,.1, S]);<br>
grid on <br>
drawnow<br>
else<br>
h = animatedline;<br>
x=pe, y=pn; z=pd;<br>
addpoints (h, x, y, z);<br>
drawnow<br>
end

Tue, 23 May 2017 15:33:05 +0000
Re: Solving system of 6 differential equations
https://www.mathworks.com/matlabcentral/newsreader/view_thread/348612#954172
Steven Lord
"Anu Antony" wrote in message <og1asf$8d6$1@newscl01ah.mathworks.com>...<br>
> <br>
> I have a system of 6 different differential equations and each of these depend on each other. I have a snippet of my code as follows. I am not a pro at mat lab. So my coefficients change at every time interval of 1 hour and I need to evaluate the solution at every change. However I cant seem to solve it. My output (temperature) keeps degrading incrementally which is completely wrong. Is there any other simpler method I can follow or something wrong with my code and method?. I seem to have exhausted all kinds of methods(tried manually doing RK4 method, ode45,explicit). Any help is greatly appreciated!<br>
<br>
See the "Systems of ODEs" and "HigherOrder ODEs" examples on this documentation page for how to set up the ODE function that you pass into the ODE solver as its first input:<br>
<br>
https://www.mathworks.com/help/matlab/math/chooseanodesolver.html<br>
<br>
Since your ODEs change every hour I would solve your ODE with a timespan of one hour, modify your ODE function to reflect the coefficient changes, use the final solution from the hour run you just completed as the initial condition for the next hour's run, then repeat this process until you've reached your final time.<br>
<br>
The BALLODE example does something like this (it doesn't need to change the ODE function but it does need to change the initial conditions), but since it doesn't know exactly how long each bounce will take it needs to use an event function. Your problem is similar but simpler, since you know each of your "bounces" is exactly 1 hour long and so can use the timespan rather than an events function to know when to finish one run and begin another.<br>
<br>
 <br>
Steve Lord<br>
slord@mathworks.com<br>
To contact Technical Support, use the Contact Us link at the top of <a href="http://www.mathworks.com">http://www.mathworks.com</a>

Tue, 23 May 2017 14:45:03 +0000
read block wise text data
https://www.mathworks.com/matlabcentral/newsreader/view_thread/348610#954171
Saravanan Mani
"Moon Datta" wrote in message <og126v$jnd$1@newscl01ah.mathworks.com>...<br>
> "Saravanan Mani" wrote in message <og0vij$eaf$1@newscl01ah.mathworks.com>...<br>
> > "Moon Datta" wrote in message <og0t5n$9d3$1@newscl01ah.mathworks.com>...<br>
> > > I am having a random text data file with different monthly blocks. Each blocks are started with a specific header line(last word is MHz). When I am trying to read the file at once I am using<br>
> > > txt = fileread ('C:\Users\hp pc\Desktop\test.txt');<br>
> > > txt1 = regexprep (txt, '.*MHz', ''); % Remove header<br>
> > > <br>
> > > But after using it I am getting the first block of data only. That is Matlab is reading the first block data only. <br>
> > > Is there any way to read the all blocks and keep them in different worksheets?<br>
> > <br>
> > Dear Moon Datta,<br>
> > <br>
> > you can see below example<br>
> > <br>
> > you read nnumber of text files from current directory.<br>
> > <br>
> > clc;<br>
> > clear;<br>
> > files_list = dir('*.txt');<br>
> > for n=1:length(files_list)<br>
> > file_name = (files_list(n).name);<br>
> > % Searching text files from current directory<br>
> > file_read = fopen(file_name,'r');<br>
> > cfilestr = fread(file_read,'*char')';<br>
> > %%% your syntex<br>
> > txt1 = regexprep (cfilestr, '.*MHz', ''); % Remove header<br>
> > %%%<br>
> > end<br>
> > <br>
> > Need some clarification, " keep them in different worksheets?" what you are expecting exactly, could you please explain in detail.<br>
> > <br>
> > Thanks & Regards,<br>
> > Saravanan<br>
> <br>
> Thanks for your kind reply. Actually I dont need to read n numbers of text files. I am having one text file. in that file ha ning data of different blocks...like<br>
> <br>
> <br>
> <br>
> 2014 1 31 1 744 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24<br>
> 24 24 24 24 24 24<br>
> foF2<br>
> 0.1 MHz<br>
> 00<br>
> 00000 10000 20000 30000 40000 50000 60000 70000 80000 90000100000110000120000130000140000150000160000170000180000190000<br>
> 200000210000220000230000 00000 10000 20000 30000 40000 50000 60000 70000 80000 90000100000110000120000130000140000150000<br>
> 160000170000180000190000200000210000220000230000 00000 10000 20000 30000 40000 50000 60000 70000 80000 90000100000110000<br>
> 120000 R135 126 117 116 106 100US 99US108 88US 72 S<br>
> <br>
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0<br>
> <br>
> <br>
> <br>
> <br>
> <br>
> <br>
> <br>
> 2014 5 31 1 744 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24<br>
> 24 24 24 24 24 24<br>
> foF2<br>
> 0.1 MHz<br>
> 00<br>
> 00000 10000 20000 30000 40000 50000 60000 70000 80000 90000100000110000120000130000140000150000160000170000180000190000<br>
> 200000210000220000230000 00000 10000 20000 30000 40000 50000 60000 70000 80000 90000100000110000120000130000140000150000<br>
> 160000170000180000190000200000210000220000230000 00000 10000 20000 30000 40000 50000 60000 70000 80000 90000100000110000<br>
> 120000 R135 126 117 116 106 100US 99US108 88US 72 S<br>
> <br>
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0<br>
> <br>
> <br>
> You can see that there are two blocks and they are separated by some spaces....I want to read the data after MHz from each block and want to keep them in workspaces....<br>
> <br>
> In this way I should have 2 mat files in workspace containg the data of block 1 and block 2 respectively. <br>
<br>
Dear Moon Datta,<br>
<br>
Thank you very much for detailed information.<br>
<br>
you can see below code.<br>
<br>
The 'Moon_Datta.txt' file contain given data information from you. I just copy paste in the text file. I am used R2010b software.<br>
<br>
clc;<br>
clear;<br>
filename = 'Moon_Datta.txt';<br>
file_read = fopen(filename,'r');<br>
cfilestr = fread(file_read,'*char')';<br>
cfileCell = textscan(cfilestr,'%s','delimiter','\n');<br>
cfileStrCell = cfileCell{1};<br>
Current_cfile = regexp(cfileStrCell,'\MHz*','match');<br>
Current_cfile_char = regexp(cfileStrCell,'0 0 0','match');<br>
det_Idx = find(cellfun(@isempty,Current_cfile) == 0);<br>
det_Idx1 = find(cellfun(@isempty,Current_cfile_char) == 0);<br>
for k = 1:length(det_Idx)<br>
text_data = cfileStrCell(det_Idx(k):det_Idx1(k));<br>
assignin('base',['text_data' num2str(k)],text_data)<br>
end<br>
clear filename file_read cfilestr cfileCell cfileStrCell Current_cfile Current_cfile_char<br>
clear text_data k det_Idx det_Idx1<br>
<br>
Please let me know if you have any concern<br>
<br>
Thanks & Regards,<br>
Saravanan<br>
Job Seeker,..... Please if you have job in your organization, Please let me know. It could be great helpful for me! Please don't mind me asking for job help.<br>

Tue, 23 May 2017 13:57:03 +0000
How can I use 'fmincon' without anonymous function with parameters?
https://www.mathworks.com/matlabcentral/newsreader/view_thread/348614#954170
YeonSoo
I want to use the 'fmincon' in simulink matlab function block. And the simulink does not support the anonymous function. And I have several parameters for calculating the objective function and the global variable can not be assigned for those parameters. Then how can i construct the objective function file for using the 'fmincon'?

Tue, 23 May 2017 13:16:03 +0000
CUDA with Matlab
https://www.mathworks.com/matlabcentral/newsreader/view_thread/348613#954169
Ming
We have a customized CUDA software compiled with mex files. The problem is that every time we run it and then run the matlab GPU array functions, it seems that Matlab takes a long time to initialize the GPU functions. Does Anyone have similar problem?

Tue, 23 May 2017 12:59:04 +0000
Re: Unknown Simulink Block
https://www.mathworks.com/matlabcentral/newsreader/view_thread/348606#954168
Navan Ruthramoorthy
"giuseppe ciavolino" wrote in message <ofvo0v$k2p$1@newscl01ah.mathworks.com>...<br>
> Hello,<br>
> I'm trying to figure out what is this block https://ibb.co/ncKFSa<br>
> but I can't find it in the Simulink library..<br>
> Can anyone help me?<br>
<br>
If you have the model, try some of these things to identify the block.<br>
<br>
1. With the block selected run, get_param(gcb, 'BlockType');<br>
 That should tell you what type of block it is. You can use that to search in the library.<br>
2. With the block selected run get_param(gcb, 'ReferenceBlock');<br>
 If the block is from a custom library this will tell you which library it is from.<br>
3. If the above did not produce any results the block may just exist only in your model. Try right clicking on the block and choose "Mask" option and then "Look under Mask" if those are enabled to investigate more.<br>
<br>
Navan

Tue, 23 May 2017 12:45:03 +0000
Solving system of 6 differential equations
https://www.mathworks.com/matlabcentral/newsreader/view_thread/348612#954167
Anu Antony
<br>
I have a system of 6 different differential equations and each of these depend on each other. I have a snippet of my code as follows. I am not a pro at mat lab. So my coefficients change at every time interval of 1 hour and I need to evaluate the solution at every change. However I cant seem to solve it. My output (temperature) keeps degrading incrementally which is completely wrong. Is there any other simpler method I can follow or something wrong with my code and method?. I seem to have exhausted all kinds of methods(tried manually doing RK4 method, ode45,explicit). Any help is greatly appreciated!

Tue, 23 May 2017 12:20:52 +0000
Re: Is it OK to use (already) optimised HyperParameters in SVM or
https://www.mathworks.com/matlabcentral/newsreader/view_thread/348597#954166
Ilya Narsky
On 5/23/2017 12:30 AM, Roohollah Milimonfared wrote:<br>
> Thanks Ilya for your time and clarification.<br>
> <br>
> Since the hyperparameters are optimised by Bayesian method using the <br>
> fivefold crossvalidation loss, can we say resubLoss(classificationSVM) <br>
> returns the fivefold crossvalidation error? or we still need to <br>
> optimise the classification SVM output according to the below script?<br>
> <br>
> % partitionedModel = crossval(classificationSVM, 'KFold', 5);<br>
> % validationAccuracy = 1  kfoldLoss(partitionedModel, 'LossFun', <br>
> 'ClassifError');<br>
> <br>
> Big Thanks,<br>
> Roohollah<br>
<br>
resubLoss never returns crossvalidated error. There is nothing in the <br>
doc or help for that method that would promise crossvalidated error.

Tue, 23 May 2017 11:00:04 +0000
simulink model input variable data error
https://www.mathworks.com/matlabcentral/newsreader/view_thread/348611#954165
kalyan velamakanni
IN the ad9361 matlab simulink model there are 2 ways two give he input ideal source and test source but if i create a matlab function block(test signall for ADSB signal generated with noise and interference at 1090 MHz and use it as input(y) to the AD9361RX simulink block I got the error<br>
<br>
<br>
<br>
Data 'y' is inferred as a variable size matrix, while its properties in the Model Explorer specify its size as inherited or fixed. Please check the 'Variable Size' check box and specify the upper bounds in the size field.1) the block does not support variablesize signals; 2) the block supports variablesize signals but needs to be configured for them<br>
<br>
<br>
<br>
I tried to change the data setting limits of the matlab function for the variable y as [1 5000]<br>
<br>
MATLAB function should not output varsize variables since the length is always predefined. Do not perform this cast in your function and this error should go away.<br>
<br>
but how can I change my matlab function to output constant size data type.<br>
<br>
note:I did the edit data for the matlab function and tried change the data setting limits of the matlab function for the variable y as [1 5000]<br>
<br>
<br>
<br>
my matlab function<br>
<br>
function y = fcn<br>
<br>
<br>
%% PARAMETERS<br>
freq_ADSB=1090e6;<br>
freq_sampling = 1e6;<br>
<br>
%% CREATION OF BITS VECTORS<br>
nb_sample_half_bit = 5; % Number of samples<br>
<br>
% Creation of bits 0,1 and absence of bits<br>
bit_one = [ones(1,nb_sample_half_bit) zeros(1,nb_sample_half_bit)]; <br>
bit_zero = [zeros(1,nb_sample_half_bit) ones(1,nb_sample_half_bit)];<br>
no_bit = [zeros(1,nb_sample_half_bit) zeros(1,nb_sample_half_bit)];<br>
<br>
%% CREATION OF THE PREAMBLE<br>
% Creation of the preamble which lasts 8 µs<br>
% preamble = 2 bits ONE, 1 abscence of pulses, 2 bits ZEROS, 3 abscence of pulses <br>
preamble = [bit_one bit_one no_bit bit_zero bit_zero no_bit no_bit no_bit];<br>
<br>
<br>
%% CREATION OF THE MESSAGE<br>
% Creation of the message which lasts 112 µs (112 bits)<br>
lengthMessage = 112;<br>
message = rand(1,nb_sample_half_bit*2*lengthMessage);<br>
<br>
%message = bit_one; % Init the message with a bit one ( can be done with bit zero)<br>
<br>
for i=0:lengthMessagenb_sample_half_bit*2<br>
test = rand(1,1); % for creating a random message<br>
if test < 0.5<br>
message = [message bit_one];<br>
else<br>
message = [message bit_zero];<br>
end<br>
end <br>
<br>
<br>
%% CREATION OF THE ADSB Signal<br>
% Perfect ADSB Signal<br>
perfect_ADSB_Signal = [preamble message];<br>
<br>
<br>
<br>
%% CREATION OF THE RF ADSB SIGNAL<br>
<br>
time=0: 1/freq_sampling:( (length(perfect_ADSB_Signal)*(1/freq_sampling)1/freq_sampling));<br>
<br>
perfect_ADSB_Signal_RF =perfect_ADSB_Signal.*sin(2*pi*freq_ADSB*time);<br>
<br>
perfect_ADSB_Signal_RF = perfect_ADSB_Signal_RF';<br>
<br>
<br>
y=coder.varsize('perfect_ADSB_Signal_RF',[1 5000]);<br>
<br>
<br>
<br>
<br>
please lezt me know where I should change so as to get a constant variable data type