Tag Archives: matlab
How to remove border from MATLAB figure
I’m trying to compare spectrogram images in a MATLAB image analyzer, but I think the white border is causing them to be overly similar. Because of the number of images I need to process, I’d really like to have it automatically generate and save the image. Here is my current code that I’m using to make and save the spectrogram.
base=filename %The code saves multiple images with the label being the filename and a specific addition to each image
figure(1003)
spectrogram(Xacc,windowx,noverlap,nfft,fs,’yaxis’)
ylim([0 5])
colormap(gray(256));
caxis([-160 40])
% title(‘Spectrogram of X’)
s1=base + "SPEC_Acc_X GS";
saveas(gcf,s1,’jpg’)
When I run it I get an image like this.
What I want is an image like this, but in order to get it I had to adjust every setting manually in the image editor. Alternately, is there a way to automatically crop saved images? That could also be a solution.
Thanks so much for the help!I’m trying to compare spectrogram images in a MATLAB image analyzer, but I think the white border is causing them to be overly similar. Because of the number of images I need to process, I’d really like to have it automatically generate and save the image. Here is my current code that I’m using to make and save the spectrogram.
base=filename %The code saves multiple images with the label being the filename and a specific addition to each image
figure(1003)
spectrogram(Xacc,windowx,noverlap,nfft,fs,’yaxis’)
ylim([0 5])
colormap(gray(256));
caxis([-160 40])
% title(‘Spectrogram of X’)
s1=base + "SPEC_Acc_X GS";
saveas(gcf,s1,’jpg’)
When I run it I get an image like this.
What I want is an image like this, but in order to get it I had to adjust every setting manually in the image editor. Alternately, is there a way to automatically crop saved images? That could also be a solution.
Thanks so much for the help! I’m trying to compare spectrogram images in a MATLAB image analyzer, but I think the white border is causing them to be overly similar. Because of the number of images I need to process, I’d really like to have it automatically generate and save the image. Here is my current code that I’m using to make and save the spectrogram.
base=filename %The code saves multiple images with the label being the filename and a specific addition to each image
figure(1003)
spectrogram(Xacc,windowx,noverlap,nfft,fs,’yaxis’)
ylim([0 5])
colormap(gray(256));
caxis([-160 40])
% title(‘Spectrogram of X’)
s1=base + "SPEC_Acc_X GS";
saveas(gcf,s1,’jpg’)
When I run it I get an image like this.
What I want is an image like this, but in order to get it I had to adjust every setting manually in the image editor. Alternately, is there a way to automatically crop saved images? That could also be a solution.
Thanks so much for the help! image editing, border removal MATLAB Answers — New Questions
How to confirm my MATLAB license can run without internet?
We have a matlab script that runs inside an autonomous vessel collecting oceanography data.
I want to confirm that the license will allow matlab to work correctly while the vessel is offshore without internet access.
How can I make sure?We have a matlab script that runs inside an autonomous vessel collecting oceanography data.
I want to confirm that the license will allow matlab to work correctly while the vessel is offshore without internet access.
How can I make sure? We have a matlab script that runs inside an autonomous vessel collecting oceanography data.
I want to confirm that the license will allow matlab to work correctly while the vessel is offshore without internet access.
How can I make sure? license, no-internet MATLAB Answers — New Questions
how to resolve fprintf error when dealing with whole numbers?
G’day,
I have a matirx containing the following values
a = [16.0541, 17];
I am trying to write these types of data along with many other variables to a json file. However, I have encountered a problem with the second value, which produces an empty cell. Here’s a simple test
for i = 1:2
fprintf(‘n%s’,’"values":{‘);
fprintf(‘n%s’,’"min":’);
fprintf(‘%s’,a(i));
fprintf(‘%s’,’,’);
fprintf(‘n%s’,’"max":’);
fprintf(‘%s’,a(i));
fprintf(‘n%s’,’},’);
end
I am assuming it has something to do with the second value being a whole number. How do I resolve this issue?
Thanks in advance.
JonG’day,
I have a matirx containing the following values
a = [16.0541, 17];
I am trying to write these types of data along with many other variables to a json file. However, I have encountered a problem with the second value, which produces an empty cell. Here’s a simple test
for i = 1:2
fprintf(‘n%s’,’"values":{‘);
fprintf(‘n%s’,’"min":’);
fprintf(‘%s’,a(i));
fprintf(‘%s’,’,’);
fprintf(‘n%s’,’"max":’);
fprintf(‘%s’,a(i));
fprintf(‘n%s’,’},’);
end
I am assuming it has something to do with the second value being a whole number. How do I resolve this issue?
Thanks in advance.
Jon G’day,
I have a matirx containing the following values
a = [16.0541, 17];
I am trying to write these types of data along with many other variables to a json file. However, I have encountered a problem with the second value, which produces an empty cell. Here’s a simple test
for i = 1:2
fprintf(‘n%s’,’"values":{‘);
fprintf(‘n%s’,’"min":’);
fprintf(‘%s’,a(i));
fprintf(‘%s’,’,’);
fprintf(‘n%s’,’"max":’);
fprintf(‘%s’,a(i));
fprintf(‘n%s’,’},’);
end
I am assuming it has something to do with the second value being a whole number. How do I resolve this issue?
Thanks in advance.
Jon fprintf MATLAB Answers — New Questions
How to change the image of .bim file
Dear All,
I have one fie as attached.
Then I wrote the code like below, and the image like below.
clc
clear all
close all
fid = fopen(‘test1.bim’, ‘r’, ‘ieee-le’);%result1.bim is your 2D planar
data = fread(fid, inf, ‘*float’);
fclose(fid);
data = reshape(data,128,128);
figure, imagesc(data)
But actually, my image supposedly to be like below:
Anyone can help me?Dear All,
I have one fie as attached.
Then I wrote the code like below, and the image like below.
clc
clear all
close all
fid = fopen(‘test1.bim’, ‘r’, ‘ieee-le’);%result1.bim is your 2D planar
data = fread(fid, inf, ‘*float’);
fclose(fid);
data = reshape(data,128,128);
figure, imagesc(data)
But actually, my image supposedly to be like below:
Anyone can help me? Dear All,
I have one fie as attached.
Then I wrote the code like below, and the image like below.
clc
clear all
close all
fid = fopen(‘test1.bim’, ‘r’, ‘ieee-le’);%result1.bim is your 2D planar
data = fread(fid, inf, ‘*float’);
fclose(fid);
data = reshape(data,128,128);
figure, imagesc(data)
But actually, my image supposedly to be like below:
Anyone can help me? digital image processing, image processing, image segmentation, image analysis MATLAB Answers — New Questions
Thingspeak – no reading data error code 0
Hi,
I’ve just tried to upload the example sketch ReadField with an Arduino R4, updating the library with WifiS3.h rather than Wifi.h. The network connection is OK.
Unfortunately, I get an error code 0 in the Serial Monitor :
"Problem reading channel. HTTP error code 0"
I d’ont konw what is wrong here and how to fix it. I’ve read it could be result to the update rate, but the delay of the example seemes to be sufficient (15s).Hi,
I’ve just tried to upload the example sketch ReadField with an Arduino R4, updating the library with WifiS3.h rather than Wifi.h. The network connection is OK.
Unfortunately, I get an error code 0 in the Serial Monitor :
"Problem reading channel. HTTP error code 0"
I d’ont konw what is wrong here and how to fix it. I’ve read it could be result to the update rate, but the delay of the example seemes to be sufficient (15s). Hi,
I’ve just tried to upload the example sketch ReadField with an Arduino R4, updating the library with WifiS3.h rather than Wifi.h. The network connection is OK.
Unfortunately, I get an error code 0 in the Serial Monitor :
"Problem reading channel. HTTP error code 0"
I d’ont konw what is wrong here and how to fix it. I’ve read it could be result to the update rate, but the delay of the example seemes to be sufficient (15s). thingspeak, error code 0, arduino MATLAB Answers — New Questions
Plotting 2 different color maps on one world map
Is it possible to plot 2 different color maps on the worldmap figure? I have a .tif file and a .nc file that are both color scales and I want to overlay them. Currently the code I have will plot them both, but using the same color scale:
figure
hold on
worldmap([69,79], [-167,-117])
colormap(‘bone’);
geoshow([.tif file] A2,R2,DisplayType="surface")
colorbar
colormap(‘winter’)
geoshow([.nc file],,’DisplayType’,’surface’, ‘FaceAlpha’, 0.2)
colorbar
Is there any way to have 2 different colormaps? Thank you!Is it possible to plot 2 different color maps on the worldmap figure? I have a .tif file and a .nc file that are both color scales and I want to overlay them. Currently the code I have will plot them both, but using the same color scale:
figure
hold on
worldmap([69,79], [-167,-117])
colormap(‘bone’);
geoshow([.tif file] A2,R2,DisplayType="surface")
colorbar
colormap(‘winter’)
geoshow([.nc file],,’DisplayType’,’surface’, ‘FaceAlpha’, 0.2)
colorbar
Is there any way to have 2 different colormaps? Thank you! Is it possible to plot 2 different color maps on the worldmap figure? I have a .tif file and a .nc file that are both color scales and I want to overlay them. Currently the code I have will plot them both, but using the same color scale:
figure
hold on
worldmap([69,79], [-167,-117])
colormap(‘bone’);
geoshow([.tif file] A2,R2,DisplayType="surface")
colorbar
colormap(‘winter’)
geoshow([.nc file],,’DisplayType’,’surface’, ‘FaceAlpha’, 0.2)
colorbar
Is there any way to have 2 different colormaps? Thank you! geoshow, colormap, worldmap MATLAB Answers — New Questions
Why do I receive Error 5201 – Unable to access services required to run MATLAB?
When I try launch to MATLAB, I get the following error:
Unable to access services required to run MATLAB (error 5201). How do I resolve this?When I try launch to MATLAB, I get the following error:
Unable to access services required to run MATLAB (error 5201). How do I resolve this? When I try launch to MATLAB, I get the following error:
Unable to access services required to run MATLAB (error 5201). How do I resolve this? MATLAB Answers — New Questions
How to access files on Matlab Drive from Thingspeak Analysis App
Is it possible to access files on my Matlab Drive from matlab code in ThingSpeak Analysis App?
I know we can do this on Matlab Online but it seems the same code does not work on ThingSpeak analysis App.
ThanksIs it possible to access files on my Matlab Drive from matlab code in ThingSpeak Analysis App?
I know we can do this on Matlab Online but it seems the same code does not work on ThingSpeak analysis App.
Thanks Is it possible to access files on my Matlab Drive from matlab code in ThingSpeak Analysis App?
I know we can do this on Matlab Online but it seems the same code does not work on ThingSpeak analysis App.
Thanks thingspeak, matlab drive, analysis app MATLAB Answers — New Questions
undo a command in matlab plotting in 2d
I have a plot in 2d with 3 waves in it now i want to remove one the wave from the plot , how can i do it without restarting from the startI have a plot in 2d with 3 waves in it now i want to remove one the wave from the plot , how can i do it without restarting from the start I have a plot in 2d with 3 waves in it now i want to remove one the wave from the plot , how can i do it without restarting from the start #plot, #2d_plotting MATLAB Answers — New Questions
Is there a way to remove the vertical line from Matlab editor window?
I want to remove the vertical line in the Matlab editor window. Please help me someone.I want to remove the vertical line in the Matlab editor window. Please help me someone. I want to remove the vertical line in the Matlab editor window. Please help me someone. matlab, editor MATLAB Answers — New Questions
How to install fuzzy logic toolbox into matlab
How to install fuzzy logic toolbox into matlab 2017How to install fuzzy logic toolbox into matlab 2017 How to install fuzzy logic toolbox into matlab 2017 matlab, toolbox, fuzzy logic MATLAB Answers — New Questions
how can i have step input signal in signal editor?
I have 3 signals for a SCARA robot. I want to input a step input for these 3 signals in the Signal Editor. How should I enter the time and data inputs in the Signal Editor?
x=[1.412,0.8696,1.412,1.412,1.821,1.545,1.8312.382,1.412]
y=[-3.142,-2.088,-3.142.-3.142,-3.142,-2.31,-3.142,-3.142,-3.142]
z=[-0.086,-0.086,-0.086,-0.186,-0.186,-0.186,-0.186,-0.386,-0.086]
t=[0,1,1.5,2,3,4,4.5,5,6]I have 3 signals for a SCARA robot. I want to input a step input for these 3 signals in the Signal Editor. How should I enter the time and data inputs in the Signal Editor?
x=[1.412,0.8696,1.412,1.412,1.821,1.545,1.8312.382,1.412]
y=[-3.142,-2.088,-3.142.-3.142,-3.142,-2.31,-3.142,-3.142,-3.142]
z=[-0.086,-0.086,-0.086,-0.186,-0.186,-0.186,-0.186,-0.386,-0.086]
t=[0,1,1.5,2,3,4,4.5,5,6] I have 3 signals for a SCARA robot. I want to input a step input for these 3 signals in the Signal Editor. How should I enter the time and data inputs in the Signal Editor?
x=[1.412,0.8696,1.412,1.412,1.821,1.545,1.8312.382,1.412]
y=[-3.142,-2.088,-3.142.-3.142,-3.142,-2.31,-3.142,-3.142,-3.142]
z=[-0.086,-0.086,-0.086,-0.186,-0.186,-0.186,-0.186,-0.386,-0.086]
t=[0,1,1.5,2,3,4,4.5,5,6] step input signal MATLAB Answers — New Questions
Unable to create a exponential graph
I am trying to make a basic tyre degredation model and I am not able to get an increasing exponential graph. I have four input block representing vital variables reagrding tyre degredation. The current model is down below. The code inside the MATLAB function block is
function y = exp_temp(u)
2 % Exponential function for temperature degradation
3 a = 0.1; % adjust this value to fit the data
4 b = 0.02; % adjust this value to fit the data
5 y = a * exp(b * u);
6 end
The graph should look like something In the second picture. What am I doing wrong.I am trying to make a basic tyre degredation model and I am not able to get an increasing exponential graph. I have four input block representing vital variables reagrding tyre degredation. The current model is down below. The code inside the MATLAB function block is
function y = exp_temp(u)
2 % Exponential function for temperature degradation
3 a = 0.1; % adjust this value to fit the data
4 b = 0.02; % adjust this value to fit the data
5 y = a * exp(b * u);
6 end
The graph should look like something In the second picture. What am I doing wrong. I am trying to make a basic tyre degredation model and I am not able to get an increasing exponential graph. I have four input block representing vital variables reagrding tyre degredation. The current model is down below. The code inside the MATLAB function block is
function y = exp_temp(u)
2 % Exponential function for temperature degradation
3 a = 0.1; % adjust this value to fit the data
4 b = 0.02; % adjust this value to fit the data
5 y = a * exp(b * u);
6 end
The graph should look like something In the second picture. What am I doing wrong. matlab, simulink MATLAB Answers — New Questions
Portfolio Optimisation using a mean/ mean absolute deviation model (linear program)
Hey everybody,
I am new to Matlab. I have recently used quadprog for the standard mean-variance model to optimise a portfolio.
I want to try several models and am currently trying to model the linear program -> mean / mean absolute deviation.
Mathematically speaking :
[URL=http://www.pic-upload.de/view-20298258/Screen-Shot-2013-08-05-at-01.05.47.png.html][IMG]http://www10.pic-upload.de/thumb/05.08.13/3hz1okoiiv24.png[/IMG][/URL]
in case that didn’t work :
http://www.pic-upload.de/view-20298258/Screen-Shot-2013-08-05-at-01.05.47.png.html
S = 872 observations I have for 9 stocks.
delta is the target return.
% This script will calculate and plot the efficient frontier for a
% mean – mean absolute deviation model in the Konno context.
% Take sample ‘Sample’ and calculate the mad -> transpose PeriodMAD
% and store variable in the workspace
PeriodMAD = mad(Sample);
PeriodMAD = PeriodMAD’;
assignin(‘base’,’PeriodMAD’,PeriodMAD);
% get number of Assets ( i am using 9 stocks)
nAssets = numel(PeriodMAD);
% Set the first targetreturn
targetreturn = 0.000001;
% Not sure if that is right -> allow none of the MAD values to lower than
% 0
nonnegativityMAD = zeros(nAssets, 1);
% Conformity with the linproq notation
f = PeriodMAD;
% Set some restrictions -> as shown in the graphic I have provided. NOt
% sure if I set them up correctly to be honest.
% PeriodDeviations includes nothing more than Observation at time(i) –
% mean of the asset (PeriodDeviations -> (9,1) vector)
% PeriodReturns -> ln returns for the observations 782 -> vector (9,1)
Aeq = [ PeriodDeviations
-PeriodDeviations
-PeriodMAD
-PeriodReturns ];
Beq = [ PeriodMAD
-PeriodMAD
nonnegativityMAD
-targetreturn];
% Set lower and upper boundaries for the weights -> 0<= x <= 1
lb = zeros(nAssets,1);
ub = ones(nAssets, 1);
% Copied that line from the quadprog example given on the internet
% changed interior-point-convex to interior-point
options = optimset(‘Algorithm’,’interior-point’);
options = optimset(options,’Display’,’iter’,’TolFun’,1e-10);
for i=1:100000;
x = linprog ( f,[],[],Aeq,Beq,lb,ub,[], options );
% Not sure if that is correct. Store respective mean in Output(1,i)
% do the same for the portfolio MAD -> is that correct?
% This is a modified "Sharpe- Ratio" or Konno Ratio. the quotient of
% the former two variables
% Finally store the weights x in Output as well -> 9 variables
% therefore Output(5,i) to Output(13,i)
Output(1,i) = x’ * PeriodReturns;
Output(2,i) = x’ * PeriodMAD;
Output(3,i) = (Output(1,i)/Output(2,i));
Output(5,i) = x(1,1);
Output(6,i) = x(2,1);
Output(7,i) = x(3,1);
Output(8,i) = x(4,1);
Output(9,i) = x(5,1);
Output(10,i) = x(6,1);
Output(11,i) = x(7,1);
Output(12,i) = x(8,1);
Output(13,i) = x(9,1);
% now increment targetreturn -> repeat the entire process as long as
% linprog finds a solutions (converges to a solution) otherwise
% stop/break
targetreturn = targetreturn + 0.000001;
if(exitflag == 1)
continue
else
break
end
end
% Find highest KonnoRatio – Quotient of Returns/Risk stored as
% maxKonnoRatio then find position in Output
maxKonnoRatio = max(Output(3,:));
[row col] = find(maxKonnoRatio == Output(3,:));
% finally create and display an array that contains all the information
% for the optimal allocation.
OptimalAll = [ Output(1,col)
Output(2,col)
Output(3,col)
0
Output(5,col)
Output(6,col)
Output(7,col)
Output(8,col)
Output(9,col) ]
% and hopefully draw the efficient frontier
plot(Output(2,i),Output(1,i))
I am stuck. I have modified so much stuff already and I keep getting error messages. currently this is the most recent one :
EDU>> MAD
Error using linprog (line 231)
The number of rows in Aeq must be the same as the number of elements of beq.
Error in MAD (line 37)
x = linprog ( f,[],[],Aeq,Beq,lb,ub,[], options );
EDU>> MAD
Error: File: MAD.m Line: 108 Column: 32
Unbalanced or unexpected parenthesis or bracket.
EDU>>
if you could please help me.
Am I at least close to a proper solution ?
Btw. : I will annualise those daily data observations – as soon as I can solve the basic problem.
I would be very grateful for some advice and/or help.
Thank you so much!
DanielHey everybody,
I am new to Matlab. I have recently used quadprog for the standard mean-variance model to optimise a portfolio.
I want to try several models and am currently trying to model the linear program -> mean / mean absolute deviation.
Mathematically speaking :
[URL=http://www.pic-upload.de/view-20298258/Screen-Shot-2013-08-05-at-01.05.47.png.html][IMG]http://www10.pic-upload.de/thumb/05.08.13/3hz1okoiiv24.png[/IMG][/URL]
in case that didn’t work :
http://www.pic-upload.de/view-20298258/Screen-Shot-2013-08-05-at-01.05.47.png.html
S = 872 observations I have for 9 stocks.
delta is the target return.
% This script will calculate and plot the efficient frontier for a
% mean – mean absolute deviation model in the Konno context.
% Take sample ‘Sample’ and calculate the mad -> transpose PeriodMAD
% and store variable in the workspace
PeriodMAD = mad(Sample);
PeriodMAD = PeriodMAD’;
assignin(‘base’,’PeriodMAD’,PeriodMAD);
% get number of Assets ( i am using 9 stocks)
nAssets = numel(PeriodMAD);
% Set the first targetreturn
targetreturn = 0.000001;
% Not sure if that is right -> allow none of the MAD values to lower than
% 0
nonnegativityMAD = zeros(nAssets, 1);
% Conformity with the linproq notation
f = PeriodMAD;
% Set some restrictions -> as shown in the graphic I have provided. NOt
% sure if I set them up correctly to be honest.
% PeriodDeviations includes nothing more than Observation at time(i) –
% mean of the asset (PeriodDeviations -> (9,1) vector)
% PeriodReturns -> ln returns for the observations 782 -> vector (9,1)
Aeq = [ PeriodDeviations
-PeriodDeviations
-PeriodMAD
-PeriodReturns ];
Beq = [ PeriodMAD
-PeriodMAD
nonnegativityMAD
-targetreturn];
% Set lower and upper boundaries for the weights -> 0<= x <= 1
lb = zeros(nAssets,1);
ub = ones(nAssets, 1);
% Copied that line from the quadprog example given on the internet
% changed interior-point-convex to interior-point
options = optimset(‘Algorithm’,’interior-point’);
options = optimset(options,’Display’,’iter’,’TolFun’,1e-10);
for i=1:100000;
x = linprog ( f,[],[],Aeq,Beq,lb,ub,[], options );
% Not sure if that is correct. Store respective mean in Output(1,i)
% do the same for the portfolio MAD -> is that correct?
% This is a modified "Sharpe- Ratio" or Konno Ratio. the quotient of
% the former two variables
% Finally store the weights x in Output as well -> 9 variables
% therefore Output(5,i) to Output(13,i)
Output(1,i) = x’ * PeriodReturns;
Output(2,i) = x’ * PeriodMAD;
Output(3,i) = (Output(1,i)/Output(2,i));
Output(5,i) = x(1,1);
Output(6,i) = x(2,1);
Output(7,i) = x(3,1);
Output(8,i) = x(4,1);
Output(9,i) = x(5,1);
Output(10,i) = x(6,1);
Output(11,i) = x(7,1);
Output(12,i) = x(8,1);
Output(13,i) = x(9,1);
% now increment targetreturn -> repeat the entire process as long as
% linprog finds a solutions (converges to a solution) otherwise
% stop/break
targetreturn = targetreturn + 0.000001;
if(exitflag == 1)
continue
else
break
end
end
% Find highest KonnoRatio – Quotient of Returns/Risk stored as
% maxKonnoRatio then find position in Output
maxKonnoRatio = max(Output(3,:));
[row col] = find(maxKonnoRatio == Output(3,:));
% finally create and display an array that contains all the information
% for the optimal allocation.
OptimalAll = [ Output(1,col)
Output(2,col)
Output(3,col)
0
Output(5,col)
Output(6,col)
Output(7,col)
Output(8,col)
Output(9,col) ]
% and hopefully draw the efficient frontier
plot(Output(2,i),Output(1,i))
I am stuck. I have modified so much stuff already and I keep getting error messages. currently this is the most recent one :
EDU>> MAD
Error using linprog (line 231)
The number of rows in Aeq must be the same as the number of elements of beq.
Error in MAD (line 37)
x = linprog ( f,[],[],Aeq,Beq,lb,ub,[], options );
EDU>> MAD
Error: File: MAD.m Line: 108 Column: 32
Unbalanced or unexpected parenthesis or bracket.
EDU>>
if you could please help me.
Am I at least close to a proper solution ?
Btw. : I will annualise those daily data observations – as soon as I can solve the basic problem.
I would be very grateful for some advice and/or help.
Thank you so much!
Daniel Hey everybody,
I am new to Matlab. I have recently used quadprog for the standard mean-variance model to optimise a portfolio.
I want to try several models and am currently trying to model the linear program -> mean / mean absolute deviation.
Mathematically speaking :
[URL=http://www.pic-upload.de/view-20298258/Screen-Shot-2013-08-05-at-01.05.47.png.html][IMG]http://www10.pic-upload.de/thumb/05.08.13/3hz1okoiiv24.png[/IMG][/URL]
in case that didn’t work :
http://www.pic-upload.de/view-20298258/Screen-Shot-2013-08-05-at-01.05.47.png.html
S = 872 observations I have for 9 stocks.
delta is the target return.
% This script will calculate and plot the efficient frontier for a
% mean – mean absolute deviation model in the Konno context.
% Take sample ‘Sample’ and calculate the mad -> transpose PeriodMAD
% and store variable in the workspace
PeriodMAD = mad(Sample);
PeriodMAD = PeriodMAD’;
assignin(‘base’,’PeriodMAD’,PeriodMAD);
% get number of Assets ( i am using 9 stocks)
nAssets = numel(PeriodMAD);
% Set the first targetreturn
targetreturn = 0.000001;
% Not sure if that is right -> allow none of the MAD values to lower than
% 0
nonnegativityMAD = zeros(nAssets, 1);
% Conformity with the linproq notation
f = PeriodMAD;
% Set some restrictions -> as shown in the graphic I have provided. NOt
% sure if I set them up correctly to be honest.
% PeriodDeviations includes nothing more than Observation at time(i) –
% mean of the asset (PeriodDeviations -> (9,1) vector)
% PeriodReturns -> ln returns for the observations 782 -> vector (9,1)
Aeq = [ PeriodDeviations
-PeriodDeviations
-PeriodMAD
-PeriodReturns ];
Beq = [ PeriodMAD
-PeriodMAD
nonnegativityMAD
-targetreturn];
% Set lower and upper boundaries for the weights -> 0<= x <= 1
lb = zeros(nAssets,1);
ub = ones(nAssets, 1);
% Copied that line from the quadprog example given on the internet
% changed interior-point-convex to interior-point
options = optimset(‘Algorithm’,’interior-point’);
options = optimset(options,’Display’,’iter’,’TolFun’,1e-10);
for i=1:100000;
x = linprog ( f,[],[],Aeq,Beq,lb,ub,[], options );
% Not sure if that is correct. Store respective mean in Output(1,i)
% do the same for the portfolio MAD -> is that correct?
% This is a modified "Sharpe- Ratio" or Konno Ratio. the quotient of
% the former two variables
% Finally store the weights x in Output as well -> 9 variables
% therefore Output(5,i) to Output(13,i)
Output(1,i) = x’ * PeriodReturns;
Output(2,i) = x’ * PeriodMAD;
Output(3,i) = (Output(1,i)/Output(2,i));
Output(5,i) = x(1,1);
Output(6,i) = x(2,1);
Output(7,i) = x(3,1);
Output(8,i) = x(4,1);
Output(9,i) = x(5,1);
Output(10,i) = x(6,1);
Output(11,i) = x(7,1);
Output(12,i) = x(8,1);
Output(13,i) = x(9,1);
% now increment targetreturn -> repeat the entire process as long as
% linprog finds a solutions (converges to a solution) otherwise
% stop/break
targetreturn = targetreturn + 0.000001;
if(exitflag == 1)
continue
else
break
end
end
% Find highest KonnoRatio – Quotient of Returns/Risk stored as
% maxKonnoRatio then find position in Output
maxKonnoRatio = max(Output(3,:));
[row col] = find(maxKonnoRatio == Output(3,:));
% finally create and display an array that contains all the information
% for the optimal allocation.
OptimalAll = [ Output(1,col)
Output(2,col)
Output(3,col)
0
Output(5,col)
Output(6,col)
Output(7,col)
Output(8,col)
Output(9,col) ]
% and hopefully draw the efficient frontier
plot(Output(2,i),Output(1,i))
I am stuck. I have modified so much stuff already and I keep getting error messages. currently this is the most recent one :
EDU>> MAD
Error using linprog (line 231)
The number of rows in Aeq must be the same as the number of elements of beq.
Error in MAD (line 37)
x = linprog ( f,[],[],Aeq,Beq,lb,ub,[], options );
EDU>> MAD
Error: File: MAD.m Line: 108 Column: 32
Unbalanced or unexpected parenthesis or bracket.
EDU>>
if you could please help me.
Am I at least close to a proper solution ?
Btw. : I will annualise those daily data observations – as soon as I can solve the basic problem.
I would be very grateful for some advice and/or help.
Thank you so much!
Daniel optimisation, portfolio, mad, linear, finance MATLAB Answers — New Questions
Why do i get a “Pin d10 reserved by servo” error when I run “writeDigitalPin” with my Arduino Uno?
I have an Arduino Uno connected to a servo motor and DC motors. If I create objects for the servo and for the DC motors, and then call "writeDigitalPin" to pin d10 where the DC motor is connected, the states of all of the pins are set to 0 and I get the following error:
"Uno pin d10 is reserved by servo. To release the resource, clear all variables holding onto this resource"
How can I fix this error?I have an Arduino Uno connected to a servo motor and DC motors. If I create objects for the servo and for the DC motors, and then call "writeDigitalPin" to pin d10 where the DC motor is connected, the states of all of the pins are set to 0 and I get the following error:
"Uno pin d10 is reserved by servo. To release the resource, clear all variables holding onto this resource"
How can I fix this error? I have an Arduino Uno connected to a servo motor and DC motors. If I create objects for the servo and for the DC motors, and then call "writeDigitalPin" to pin d10 where the DC motor is connected, the states of all of the pins are set to 0 and I get the following error:
"Uno pin d10 is reserved by servo. To release the resource, clear all variables holding onto this resource"
How can I fix this error? arduino, servo, writedigitalpin MATLAB Answers — New Questions
Simulation of nonlinear simulation oscillating to infinity
I am simulating a wind turbine with a flexible drivetrain in simulink. I am using a two mass model to model the oscillations on the drivetrain.
Whenever I run a simulation with a smooth change in the power output of the turbine it ends up oscillating and the simulation quits with the error message:
"Solver encountered an error while simulating model ‘WecsNoConverter’ at time 47.9683593447728 and cannot continue. Please check the model for errors.
Nonlinear iteration is not converging with step size reduced to hmin (1.70418E-13) at time 47.9684. Try reducing the minimum step size and/or relax the relative error tolerance."
I am using ode15s as the solver. I have tried relaxing the relative error tolerance but it appears to make no difference. Enabling shape preservation makes no difference. Decreasing the max order increases the lenght of time before the system oscillates to infinity. The results above are with a max order of 1. Any max order of 2-4 makes results in the above behaviour happening sooner. I have tried other solvers but ode15s gives me the best results
One thing which fixes the simulation is to increase the damping term on the two mass model. Which results in the smooth output as shown below. However, this means the model is not accurate to the original turbine, so this is not an option.
Are there any other options I can try to get the simulation to run the full length of time?I am simulating a wind turbine with a flexible drivetrain in simulink. I am using a two mass model to model the oscillations on the drivetrain.
Whenever I run a simulation with a smooth change in the power output of the turbine it ends up oscillating and the simulation quits with the error message:
"Solver encountered an error while simulating model ‘WecsNoConverter’ at time 47.9683593447728 and cannot continue. Please check the model for errors.
Nonlinear iteration is not converging with step size reduced to hmin (1.70418E-13) at time 47.9684. Try reducing the minimum step size and/or relax the relative error tolerance."
I am using ode15s as the solver. I have tried relaxing the relative error tolerance but it appears to make no difference. Enabling shape preservation makes no difference. Decreasing the max order increases the lenght of time before the system oscillates to infinity. The results above are with a max order of 1. Any max order of 2-4 makes results in the above behaviour happening sooner. I have tried other solvers but ode15s gives me the best results
One thing which fixes the simulation is to increase the damping term on the two mass model. Which results in the smooth output as shown below. However, this means the model is not accurate to the original turbine, so this is not an option.
Are there any other options I can try to get the simulation to run the full length of time? I am simulating a wind turbine with a flexible drivetrain in simulink. I am using a two mass model to model the oscillations on the drivetrain.
Whenever I run a simulation with a smooth change in the power output of the turbine it ends up oscillating and the simulation quits with the error message:
"Solver encountered an error while simulating model ‘WecsNoConverter’ at time 47.9683593447728 and cannot continue. Please check the model for errors.
Nonlinear iteration is not converging with step size reduced to hmin (1.70418E-13) at time 47.9684. Try reducing the minimum step size and/or relax the relative error tolerance."
I am using ode15s as the solver. I have tried relaxing the relative error tolerance but it appears to make no difference. Enabling shape preservation makes no difference. Decreasing the max order increases the lenght of time before the system oscillates to infinity. The results above are with a max order of 1. Any max order of 2-4 makes results in the above behaviour happening sooner. I have tried other solvers but ode15s gives me the best results
One thing which fixes the simulation is to increase the damping term on the two mass model. Which results in the smooth output as shown below. However, this means the model is not accurate to the original turbine, so this is not an option.
Are there any other options I can try to get the simulation to run the full length of time? nonlinear, simulink, simulation, unstable, oscillation, ode, ode15s, instability MATLAB Answers — New Questions
I’m trying to solve a 2nd order ode with ode45, but have no idea where to start.
This the ode with conditions I’m trying to solve and the code below is as far as I got. It would be appreciated if I could get a detailed step by step to help solve this.
%initial conditions
y0 = [0 1];
tspan = [1 4];This the ode with conditions I’m trying to solve and the code below is as far as I got. It would be appreciated if I could get a detailed step by step to help solve this.
%initial conditions
y0 = [0 1];
tspan = [1 4]; This the ode with conditions I’m trying to solve and the code below is as far as I got. It would be appreciated if I could get a detailed step by step to help solve this.
%initial conditions
y0 = [0 1];
tspan = [1 4]; ode45, ode MATLAB Answers — New Questions
Hodrick-Prescott filter with smoothing factor as parameter
Hi i’m trying to parametrize Hodrick-Prescott filter (HP) as a function of smoothing parameter. Simple xy plot with the smoothing factor as parameter. I post my code below
excel=readmatrix("COMEX_SIZ2024, 1D_1f4e1.csv");
price=excel(:,6);
lambda=500:500:5500;
>> for pp=1:length(lambda)
[Trend(length(price),pp),Cyclical(length(price),pp)]=hpfilter(price,Smoothing=lambda(pp));
end
ERROR: Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
I’m using a for loop to impile the lambda on columns and calculation (x=price) on rows. However it doesnt seem to work.
Where is my error? ThanksHi i’m trying to parametrize Hodrick-Prescott filter (HP) as a function of smoothing parameter. Simple xy plot with the smoothing factor as parameter. I post my code below
excel=readmatrix("COMEX_SIZ2024, 1D_1f4e1.csv");
price=excel(:,6);
lambda=500:500:5500;
>> for pp=1:length(lambda)
[Trend(length(price),pp),Cyclical(length(price),pp)]=hpfilter(price,Smoothing=lambda(pp));
end
ERROR: Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
I’m using a for loop to impile the lambda on columns and calculation (x=price) on rows. However it doesnt seem to work.
Where is my error? Thanks Hi i’m trying to parametrize Hodrick-Prescott filter (HP) as a function of smoothing parameter. Simple xy plot with the smoothing factor as parameter. I post my code below
excel=readmatrix("COMEX_SIZ2024, 1D_1f4e1.csv");
price=excel(:,6);
lambda=500:500:5500;
>> for pp=1:length(lambda)
[Trend(length(price),pp),Cyclical(length(price),pp)]=hpfilter(price,Smoothing=lambda(pp));
end
ERROR: Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
I’m using a for loop to impile the lambda on columns and calculation (x=price) on rows. However it doesnt seem to work.
Where is my error? Thanks hp filter, parameter, for loop, cycle MATLAB Answers — New Questions
Function file does not work
If I save a function in a file it is not work even I save the function file in the same folder of the code
the error is
‘Undefined function ‘Crouts1A’ for input arguments of type ‘double’.’
but if I write the function in the last code it is work.. how can I fix it.
My version Matlab is R2024aIf I save a function in a file it is not work even I save the function file in the same folder of the code
the error is
‘Undefined function ‘Crouts1A’ for input arguments of type ‘double’.’
but if I write the function in the last code it is work.. how can I fix it.
My version Matlab is R2024a If I save a function in a file it is not work even I save the function file in the same folder of the code
the error is
‘Undefined function ‘Crouts1A’ for input arguments of type ‘double’.’
but if I write the function in the last code it is work.. how can I fix it.
My version Matlab is R2024a function file MATLAB Answers — New Questions
Licensing error: -8,523.
I have just installed matlab. But i get an error. I researched cause of the error. I opened and checked the license file. I haven’t got HostID in license file.
My license file:
# BEGIN————–BEGIN————–BEGIN
# DO NOT EDIT THIS FILE. Any changes will be overwritten.
# MathWorks license passcode file.
#LicenseNo: my license numberI have just installed matlab. But i get an error. I researched cause of the error. I opened and checked the license file. I haven’t got HostID in license file.
My license file:
# BEGIN————–BEGIN————–BEGIN
# DO NOT EDIT THIS FILE. Any changes will be overwritten.
# MathWorks license passcode file.
#LicenseNo: my license number I have just installed matlab. But i get an error. I researched cause of the error. I opened and checked the license file. I haven’t got HostID in license file.
My license file:
# BEGIN————–BEGIN————–BEGIN
# DO NOT EDIT THIS FILE. Any changes will be overwritten.
# MathWorks license passcode file.
#LicenseNo: my license number error MATLAB Answers — New Questions