Category: Matlab
Category Archives: Matlab
How to generate c code for simulink example model, but just for a certain block.
I am using simulink example model titled "Grid tied inverter optimal current control" and i want to generate the c code for hardware implementation for the TI F28379D device. The issue is , the c code generted create dmany lines of code for the whole model but i just want the controller (DSP) code. how do i do that?I am using simulink example model titled "Grid tied inverter optimal current control" and i want to generate the c code for hardware implementation for the TI F28379D device. The issue is , the c code generted create dmany lines of code for the whole model but i just want the controller (DSP) code. how do i do that? I am using simulink example model titled "Grid tied inverter optimal current control" and i want to generate the c code for hardware implementation for the TI F28379D device. The issue is , the c code generted create dmany lines of code for the whole model but i just want the controller (DSP) code. how do i do that? simulink, code generation, dsp, hardware, embedded coder MATLAB Answers — New Questions
How do I correct the ‘Invalid root outport connection in the referenced model ‘referenced_model’ error in Simulink 7.2 (R2008a)?
I have a model, which contains a referenced model. When I update the main model I receive the following error:
ERROR: Invalid root outport connection in the referenced model ‘referenced_model’. Two different blocks drive the root Outport block 1. To be a valid connection, the root Outport block must be driven by one source port. Use the ‘Invalid Root Inport and Outport block connection’ option on the ‘Model Referencing’ group of the Diagnostics page of the Configuration Parameters dialog box to control reporting of this condition.
What can I do in order to avoid this error?I have a model, which contains a referenced model. When I update the main model I receive the following error:
ERROR: Invalid root outport connection in the referenced model ‘referenced_model’. Two different blocks drive the root Outport block 1. To be a valid connection, the root Outport block must be driven by one source port. Use the ‘Invalid Root Inport and Outport block connection’ option on the ‘Model Referencing’ group of the Diagnostics page of the Configuration Parameters dialog box to control reporting of this condition.
What can I do in order to avoid this error? I have a model, which contains a referenced model. When I update the main model I receive the following error:
ERROR: Invalid root outport connection in the referenced model ‘referenced_model’. Two different blocks drive the root Outport block 1. To be a valid connection, the root Outport block must be driven by one source port. Use the ‘Invalid Root Inport and Outport block connection’ option on the ‘Model Referencing’ group of the Diagnostics page of the Configuration Parameters dialog box to control reporting of this condition.
What can I do in order to avoid this error? MATLAB Answers — New Questions
image overlays to make playing card
Hi I am trying to overlap a picture of a red diamond ontop of another image that I created so that it looks like a playing card. Bleow is the script for the playing card is there a way to combine the red diamond image ontop of the mona lisa?
The mona.lisa.jpg was a just a random jpg i found of mona lisa and crop/coppied/and then flipped to give the effect of a playing card
Also the red diamond was just an image that i pulled off the internet
pic = imread(‘monalisa.jpg’);
top_mona = pic(1:550, 1:743, :);
flipped_mona = imrotate(top_mona,180,’bicubic’);
complete_card = [top_mona; flipped_mona];
imshow(complete_card)Hi I am trying to overlap a picture of a red diamond ontop of another image that I created so that it looks like a playing card. Bleow is the script for the playing card is there a way to combine the red diamond image ontop of the mona lisa?
The mona.lisa.jpg was a just a random jpg i found of mona lisa and crop/coppied/and then flipped to give the effect of a playing card
Also the red diamond was just an image that i pulled off the internet
pic = imread(‘monalisa.jpg’);
top_mona = pic(1:550, 1:743, :);
flipped_mona = imrotate(top_mona,180,’bicubic’);
complete_card = [top_mona; flipped_mona];
imshow(complete_card) Hi I am trying to overlap a picture of a red diamond ontop of another image that I created so that it looks like a playing card. Bleow is the script for the playing card is there a way to combine the red diamond image ontop of the mona lisa?
The mona.lisa.jpg was a just a random jpg i found of mona lisa and crop/coppied/and then flipped to give the effect of a playing card
Also the red diamond was just an image that i pulled off the internet
pic = imread(‘monalisa.jpg’);
top_mona = pic(1:550, 1:743, :);
flipped_mona = imrotate(top_mona,180,’bicubic’);
complete_card = [top_mona; flipped_mona];
imshow(complete_card) overlaping images MATLAB Answers — New Questions
GammatoneFIlterBank produces different results inside/outside user function
This post may be difficult to answer because the data I’m using can’t be released to the public (yet)…
I’m running chirp sweep responses through Matlab’s built-in gammatonefilterbank structure. I have to process thousands of files in this way and so I pass the filter object and several waveform matrices to a function that I’ve written. As part of my function, I run the lines
signal_reference = sweeps_averaged(first_index:first_index+49999,3,i);
A = gammaFiltBank(signal_reference);
plot(A);
which, for the waveform in question, produces the graph below when I pause afterwards. Notice the large spikes at the beginning of the filtered outputs.
If I pause in the debugger and run those exact same lines again, I get the following graph of outputs below. Notice that the spikes are now gone.
Of the thousands of waveforms that I need to process, this error only occurs in roughly half a dozen of them. I can cut off the first 1000ish samples and get good results, but it’s forcing me to question the results overall – I’m not sure if the filter bank is producing other errors that I’m unaware of until I know the root cause.
Any thoughts on what might be causing this? Am I missing something simple? I’m using R2022A on a Windows 11 64-bit Dell desktop.This post may be difficult to answer because the data I’m using can’t be released to the public (yet)…
I’m running chirp sweep responses through Matlab’s built-in gammatonefilterbank structure. I have to process thousands of files in this way and so I pass the filter object and several waveform matrices to a function that I’ve written. As part of my function, I run the lines
signal_reference = sweeps_averaged(first_index:first_index+49999,3,i);
A = gammaFiltBank(signal_reference);
plot(A);
which, for the waveform in question, produces the graph below when I pause afterwards. Notice the large spikes at the beginning of the filtered outputs.
If I pause in the debugger and run those exact same lines again, I get the following graph of outputs below. Notice that the spikes are now gone.
Of the thousands of waveforms that I need to process, this error only occurs in roughly half a dozen of them. I can cut off the first 1000ish samples and get good results, but it’s forcing me to question the results overall – I’m not sure if the filter bank is producing other errors that I’m unaware of until I know the root cause.
Any thoughts on what might be causing this? Am I missing something simple? I’m using R2022A on a Windows 11 64-bit Dell desktop. This post may be difficult to answer because the data I’m using can’t be released to the public (yet)…
I’m running chirp sweep responses through Matlab’s built-in gammatonefilterbank structure. I have to process thousands of files in this way and so I pass the filter object and several waveform matrices to a function that I’ve written. As part of my function, I run the lines
signal_reference = sweeps_averaged(first_index:first_index+49999,3,i);
A = gammaFiltBank(signal_reference);
plot(A);
which, for the waveform in question, produces the graph below when I pause afterwards. Notice the large spikes at the beginning of the filtered outputs.
If I pause in the debugger and run those exact same lines again, I get the following graph of outputs below. Notice that the spikes are now gone.
Of the thousands of waveforms that I need to process, this error only occurs in roughly half a dozen of them. I can cut off the first 1000ish samples and get good results, but it’s forcing me to question the results overall – I’m not sure if the filter bank is producing other errors that I’m unaware of until I know the root cause.
Any thoughts on what might be causing this? Am I missing something simple? I’m using R2022A on a Windows 11 64-bit Dell desktop. gammatonefilterbank, filtering MATLAB Answers — New Questions
Drag histogram to adjust contrast
Hello,
I would like to create an contrast adjustment tool similar to incontrast() function that can adjust contrast by dragging the histogram bars. I cannot use imcotrast because I want to use the histogram in a gui. Can anyone please give me some hint how can I start making this tool?
Thanks in advanceHello,
I would like to create an contrast adjustment tool similar to incontrast() function that can adjust contrast by dragging the histogram bars. I cannot use imcotrast because I want to use the histogram in a gui. Can anyone please give me some hint how can I start making this tool?
Thanks in advance Hello,
I would like to create an contrast adjustment tool similar to incontrast() function that can adjust contrast by dragging the histogram bars. I cannot use imcotrast because I want to use the histogram in a gui. Can anyone please give me some hint how can I start making this tool?
Thanks in advance image processing, histogram MATLAB Answers — New Questions
How to export Plecs blockset model to Simulink model?
HI
I want to export a PLECS blockset model to simulink. I want to remove the PLECS libraries and only use simulink for my simulation.
How can I save time by exporting and not constructing the model from scratch again in simulink?
Thank You
SnehaHI
I want to export a PLECS blockset model to simulink. I want to remove the PLECS libraries and only use simulink for my simulation.
How can I save time by exporting and not constructing the model from scratch again in simulink?
Thank You
Sneha HI
I want to export a PLECS blockset model to simulink. I want to remove the PLECS libraries and only use simulink for my simulation.
How can I save time by exporting and not constructing the model from scratch again in simulink?
Thank You
Sneha plecs blockset, simulink, export blockset to simulink MATLAB Answers — New Questions
Coor image enhancement in spatial domain
Can any one suggest some matlab code for enhancing luminanace?Can any one suggest some matlab code for enhancing luminanace? Can any one suggest some matlab code for enhancing luminanace? luminance enhancement, unclear MATLAB Answers — New Questions
Problem when using quadprog solver with the ‘active-set’ algorithm
I don’t know what’s the best way to explain it, but basically I am unable to solve an optimization problem with function quadprog and active-set algorithm while interior-point did it with no problems. The exit flag that I get is 0 (The maximum number of iterations was reached. Solution x might be suboptimal or infeasible). I don’t understand, since the only thing that changes from the interior-point case is the fact that I now have to give an initial value as input. I don’t see why it would be the number of iterations either, I’ve already tried to increase it. I have also tried to debug it but when I try to step into the asqpdense function it takes me to the optimget function, so I don´t really know what is going on.
My code is a little extense and it calls many custom functions, so I don´t know what´s the best way upload it here. It is a MPC problem based on the code provided in GitHub – ARMSLab/slmpc: Successive Linearization Model Predictive Control and explained in Successive linearization based model predictive control of variable stiffness actuated robots | IEEE Conference Publication | IEEE Xplore. It seems that I need to have the solver options set to use the active-set algorithm in order to generate code (which I need), so that’s why I am trying to make active-set work.I don’t know what’s the best way to explain it, but basically I am unable to solve an optimization problem with function quadprog and active-set algorithm while interior-point did it with no problems. The exit flag that I get is 0 (The maximum number of iterations was reached. Solution x might be suboptimal or infeasible). I don’t understand, since the only thing that changes from the interior-point case is the fact that I now have to give an initial value as input. I don’t see why it would be the number of iterations either, I’ve already tried to increase it. I have also tried to debug it but when I try to step into the asqpdense function it takes me to the optimget function, so I don´t really know what is going on.
My code is a little extense and it calls many custom functions, so I don´t know what´s the best way upload it here. It is a MPC problem based on the code provided in GitHub – ARMSLab/slmpc: Successive Linearization Model Predictive Control and explained in Successive linearization based model predictive control of variable stiffness actuated robots | IEEE Conference Publication | IEEE Xplore. It seems that I need to have the solver options set to use the active-set algorithm in order to generate code (which I need), so that’s why I am trying to make active-set work. I don’t know what’s the best way to explain it, but basically I am unable to solve an optimization problem with function quadprog and active-set algorithm while interior-point did it with no problems. The exit flag that I get is 0 (The maximum number of iterations was reached. Solution x might be suboptimal or infeasible). I don’t understand, since the only thing that changes from the interior-point case is the fact that I now have to give an initial value as input. I don’t see why it would be the number of iterations either, I’ve already tried to increase it. I have also tried to debug it but when I try to step into the asqpdense function it takes me to the optimget function, so I don´t really know what is going on.
My code is a little extense and it calls many custom functions, so I don´t know what´s the best way upload it here. It is a MPC problem based on the code provided in GitHub – ARMSLab/slmpc: Successive Linearization Model Predictive Control and explained in Successive linearization based model predictive control of variable stiffness actuated robots | IEEE Conference Publication | IEEE Xplore. It seems that I need to have the solver options set to use the active-set algorithm in order to generate code (which I need), so that’s why I am trying to make active-set work. mpc, quadprog, active-set, optimization, asqpdense MATLAB Answers — New Questions
Poor imshow image quality
Hi I am trying to get a figure into a plot using imshow nd the results I get are really poor quality
this is the original figure:
this is what I get:
Increasing the size of the figure, does make the quality slightly better but it is still not any close to the original
the code I ued is:
imshow(‘Truss.png’,’border’,’tight’,’InitialMagnification’,200)
I used border tight, and initial magnification but they dont seem to change anything all, with respect the size and quality
any help is appreciated
thanksHi I am trying to get a figure into a plot using imshow nd the results I get are really poor quality
this is the original figure:
this is what I get:
Increasing the size of the figure, does make the quality slightly better but it is still not any close to the original
the code I ued is:
imshow(‘Truss.png’,’border’,’tight’,’InitialMagnification’,200)
I used border tight, and initial magnification but they dont seem to change anything all, with respect the size and quality
any help is appreciated
thanks Hi I am trying to get a figure into a plot using imshow nd the results I get are really poor quality
this is the original figure:
this is what I get:
Increasing the size of the figure, does make the quality slightly better but it is still not any close to the original
the code I ued is:
imshow(‘Truss.png’,’border’,’tight’,’InitialMagnification’,200)
I used border tight, and initial magnification but they dont seem to change anything all, with respect the size and quality
any help is appreciated
thanks image processing, digital image processing, image analysis, image, image segmentation, image acquisition MATLAB Answers — New Questions
Reading PCAP files on Matlab
I am trying to read PCAP files on matlab. Can anyone suggest how to do so?I am trying to read PCAP files on matlab. Can anyone suggest how to do so? I am trying to read PCAP files on matlab. Can anyone suggest how to do so? wlan MATLAB Answers — New Questions
How to italicize a portion of a plot label while keeping the sans-serif font?
Hi, currently I have this:
I would only like a portion of a label, say c/R_p [-], to be italicized.
This is what I do to get the above upper x-label:
xlabel(ax2, ‘{fontfamily{cmss}selectfont Chord $mathsf{c/R_p} , textsf[-]$}’, ‘Interpreter’, ‘latex’);
I tried combining mathsf with mathit, but, depending on who I use first, either I get no italics or I get italics but in the standard latex font (hence, I lose sans-serif).
I know this can be done somehow, as here they managed to do it:
Thanks for your help!Hi, currently I have this:
I would only like a portion of a label, say c/R_p [-], to be italicized.
This is what I do to get the above upper x-label:
xlabel(ax2, ‘{fontfamily{cmss}selectfont Chord $mathsf{c/R_p} , textsf[-]$}’, ‘Interpreter’, ‘latex’);
I tried combining mathsf with mathit, but, depending on who I use first, either I get no italics or I get italics but in the standard latex font (hence, I lose sans-serif).
I know this can be done somehow, as here they managed to do it:
Thanks for your help! Hi, currently I have this:
I would only like a portion of a label, say c/R_p [-], to be italicized.
This is what I do to get the above upper x-label:
xlabel(ax2, ‘{fontfamily{cmss}selectfont Chord $mathsf{c/R_p} , textsf[-]$}’, ‘Interpreter’, ‘latex’);
I tried combining mathsf with mathit, but, depending on who I use first, either I get no italics or I get italics but in the standard latex font (hence, I lose sans-serif).
I know this can be done somehow, as here they managed to do it:
Thanks for your help! plot, font, latex, label, mathsf, mathit, sans-serif, italics MATLAB Answers — New Questions
Detecting heart rate and more from ECG
This is an assigment and if possible just want to make sure if my work is correct, I’m especially unsure about the graphs.
We’re given and ECG signal (that’s supposed to be of a healthy person) and have to find:
Detect QRS complex. (output:waveform)
Heart Rate. (output:numeric)
Respiratory Rate. (output:numeric and graphical)
Heart Rate Variability. (output:waveform)
Sampling frequency is given as fs=500Hz.
I’ve attached the ECG signal and the code functions I used.
This is the main code used to call the functions:
% Load data
matstruct = load(‘ECGdata.mat’);
ecg = matstruct.x;
fs = 500; % Sampling frequency
t = (0:length(ecg)-1)/fs;
gr = 1;
% Detect QRS complexes
[qrs_amp_raw, qrs_i_raw, delay] = pan_tompkin(ecg, fs, gr);
QRS=pan_tompkin(ecg, fs, 0);
Results:
% Calculate Heart Rate
avg_heart_rate = calculate_heart_rate(ecg, fs, gr);
Output: Average Heart Rate: 66.96 bpm
(note: avergae herat rate is between 60 and 100 beats per minute.)
% Calculate Respiration Rate
[resp_rate, resp_signal] = calculate_respiratory_rate(ecg, fs, qrs_i_raw);
Output: Respiration Rate: 16.9997 breaths per minute
(not: avergae respiratory rate are between 12-20 breaths per minute for an adult.)
% Calculate Heart Rate Variability
HRV = calculateHRV(QRS, fs);This is an assigment and if possible just want to make sure if my work is correct, I’m especially unsure about the graphs.
We’re given and ECG signal (that’s supposed to be of a healthy person) and have to find:
Detect QRS complex. (output:waveform)
Heart Rate. (output:numeric)
Respiratory Rate. (output:numeric and graphical)
Heart Rate Variability. (output:waveform)
Sampling frequency is given as fs=500Hz.
I’ve attached the ECG signal and the code functions I used.
This is the main code used to call the functions:
% Load data
matstruct = load(‘ECGdata.mat’);
ecg = matstruct.x;
fs = 500; % Sampling frequency
t = (0:length(ecg)-1)/fs;
gr = 1;
% Detect QRS complexes
[qrs_amp_raw, qrs_i_raw, delay] = pan_tompkin(ecg, fs, gr);
QRS=pan_tompkin(ecg, fs, 0);
Results:
% Calculate Heart Rate
avg_heart_rate = calculate_heart_rate(ecg, fs, gr);
Output: Average Heart Rate: 66.96 bpm
(note: avergae herat rate is between 60 and 100 beats per minute.)
% Calculate Respiration Rate
[resp_rate, resp_signal] = calculate_respiratory_rate(ecg, fs, qrs_i_raw);
Output: Respiration Rate: 16.9997 breaths per minute
(not: avergae respiratory rate are between 12-20 breaths per minute for an adult.)
% Calculate Heart Rate Variability
HRV = calculateHRV(QRS, fs); This is an assigment and if possible just want to make sure if my work is correct, I’m especially unsure about the graphs.
We’re given and ECG signal (that’s supposed to be of a healthy person) and have to find:
Detect QRS complex. (output:waveform)
Heart Rate. (output:numeric)
Respiratory Rate. (output:numeric and graphical)
Heart Rate Variability. (output:waveform)
Sampling frequency is given as fs=500Hz.
I’ve attached the ECG signal and the code functions I used.
This is the main code used to call the functions:
% Load data
matstruct = load(‘ECGdata.mat’);
ecg = matstruct.x;
fs = 500; % Sampling frequency
t = (0:length(ecg)-1)/fs;
gr = 1;
% Detect QRS complexes
[qrs_amp_raw, qrs_i_raw, delay] = pan_tompkin(ecg, fs, gr);
QRS=pan_tompkin(ecg, fs, 0);
Results:
% Calculate Heart Rate
avg_heart_rate = calculate_heart_rate(ecg, fs, gr);
Output: Average Heart Rate: 66.96 bpm
(note: avergae herat rate is between 60 and 100 beats per minute.)
% Calculate Respiration Rate
[resp_rate, resp_signal] = calculate_respiratory_rate(ecg, fs, qrs_i_raw);
Output: Respiration Rate: 16.9997 breaths per minute
(not: avergae respiratory rate are between 12-20 breaths per minute for an adult.)
% Calculate Heart Rate Variability
HRV = calculateHRV(QRS, fs); homework, ecg, heart-rate, hrv, signal processing, pan_tompkin, qrs, respiratory MATLAB Answers — New Questions
Failed to open serial port COM3 to communicate with board Uno.
Encounter this error when i tried to connect my arduino board with my matlab :Failed to open serial port COM3 to communicate with board Uno. Make sure there is no other
MATLAB arduino object for this board. For troubleshooting, see Arduino Hardware
Troubleshooting.
Can anyone solve this?Encounter this error when i tried to connect my arduino board with my matlab :Failed to open serial port COM3 to communicate with board Uno. Make sure there is no other
MATLAB arduino object for this board. For troubleshooting, see Arduino Hardware
Troubleshooting.
Can anyone solve this? Encounter this error when i tried to connect my arduino board with my matlab :Failed to open serial port COM3 to communicate with board Uno. Make sure there is no other
MATLAB arduino object for this board. For troubleshooting, see Arduino Hardware
Troubleshooting.
Can anyone solve this? arduino MATLAB Answers — New Questions
How to model in simscape a system where output torque is a sum of 2 torque input sources
Hello,
How can we model in simscape a system where output torque is a sum of 2 torque input sources. Please note that both input and output shafts are rotationing with same rotational speed to make the system simpler.
Example is 5 gear setup with 2 idler gears. 1st and 5th gear are inputs sources, 3rd is the output gear and 2nd & 4th are idler gears.
Thanks
JacobHello,
How can we model in simscape a system where output torque is a sum of 2 torque input sources. Please note that both input and output shafts are rotationing with same rotational speed to make the system simpler.
Example is 5 gear setup with 2 idler gears. 1st and 5th gear are inputs sources, 3rd is the output gear and 2nd & 4th are idler gears.
Thanks
Jacob Hello,
How can we model in simscape a system where output torque is a sum of 2 torque input sources. Please note that both input and output shafts are rotationing with same rotational speed to make the system simpler.
Example is 5 gear setup with 2 idler gears. 1st and 5th gear are inputs sources, 3rd is the output gear and 2nd & 4th are idler gears.
Thanks
Jacob simscape, simulation MATLAB Answers — New Questions
Axis exponent missing when using exportgraphics to export figure in pdf vector format (or image)
Hi,
When I use exportgraphics to export a figure in pdf vector graphics format (or even image formats such as .png, .tiff), any axis exponents from the figure are missing in the output export file. For my application, I need to export the figure in vector format.
Example code to generate figure:
fig1 = figure(1);
plot(rand(10,1)*10^-5)
exportgraphics(fig1,’testMissingAxisExponent01.pdf’,’ContentType’,’vector’);
Example figure exported by using ‘Save As’ in MATLAB figure GUI (which properly shows the axis exponent):
Example figure generated from exportgraphics (with the missing axis exponent):
I first discovered this issue when working with plots in nested tiles using tiledlayouts and tried increasing the padding with no success. However, this issue seems to be related to exportgraphics.
Any solutions or workarounds? Thank you!Hi,
When I use exportgraphics to export a figure in pdf vector graphics format (or even image formats such as .png, .tiff), any axis exponents from the figure are missing in the output export file. For my application, I need to export the figure in vector format.
Example code to generate figure:
fig1 = figure(1);
plot(rand(10,1)*10^-5)
exportgraphics(fig1,’testMissingAxisExponent01.pdf’,’ContentType’,’vector’);
Example figure exported by using ‘Save As’ in MATLAB figure GUI (which properly shows the axis exponent):
Example figure generated from exportgraphics (with the missing axis exponent):
I first discovered this issue when working with plots in nested tiles using tiledlayouts and tried increasing the padding with no success. However, this issue seems to be related to exportgraphics.
Any solutions or workarounds? Thank you! Hi,
When I use exportgraphics to export a figure in pdf vector graphics format (or even image formats such as .png, .tiff), any axis exponents from the figure are missing in the output export file. For my application, I need to export the figure in vector format.
Example code to generate figure:
fig1 = figure(1);
plot(rand(10,1)*10^-5)
exportgraphics(fig1,’testMissingAxisExponent01.pdf’,’ContentType’,’vector’);
Example figure exported by using ‘Save As’ in MATLAB figure GUI (which properly shows the axis exponent):
Example figure generated from exportgraphics (with the missing axis exponent):
I first discovered this issue when working with plots in nested tiles using tiledlayouts and tried increasing the padding with no success. However, this issue seems to be related to exportgraphics.
Any solutions or workarounds? Thank you! exportgraphics, axis, missing, exponent, label MATLAB Answers — New Questions
With the new ODE command (matlab 2024a), I’d like to parametrize the ICs and make, for example, x0=[p(1); p(5)] and then compute SENSITIVITIES!
Hi, I was pleased to see that the SUNDIAL routines now become available on a lower level with the new ODE command. I’d like to use CVODES for computation of a solution + parametric sensitivities. However, I need to make one (or more) of the ICs for x (say, x0) to be parameters instead of numerical values. Right now this is not possible.
Are you intending to make the IC a function handle, so that I can say
x0 = @(p) [p(1); p(5)]
where the dynamics are given by a non-linear state space model xdot = f(x,u,p) and x is the vector with state variables x_i, for example? Would be really nice to have this, since then I can perform my analysis. I have a work around now, but do not like this solution. My ultimate goal is to include automatic differentation for all Jacobi matrices, including the IC (!), and get a very accurate solution for the sensitivities in this way.
Thanks in advance for your help.Hi, I was pleased to see that the SUNDIAL routines now become available on a lower level with the new ODE command. I’d like to use CVODES for computation of a solution + parametric sensitivities. However, I need to make one (or more) of the ICs for x (say, x0) to be parameters instead of numerical values. Right now this is not possible.
Are you intending to make the IC a function handle, so that I can say
x0 = @(p) [p(1); p(5)]
where the dynamics are given by a non-linear state space model xdot = f(x,u,p) and x is the vector with state variables x_i, for example? Would be really nice to have this, since then I can perform my analysis. I have a work around now, but do not like this solution. My ultimate goal is to include automatic differentation for all Jacobi matrices, including the IC (!), and get a very accurate solution for the sensitivities in this way.
Thanks in advance for your help. Hi, I was pleased to see that the SUNDIAL routines now become available on a lower level with the new ODE command. I’d like to use CVODES for computation of a solution + parametric sensitivities. However, I need to make one (or more) of the ICs for x (say, x0) to be parameters instead of numerical values. Right now this is not possible.
Are you intending to make the IC a function handle, so that I can say
x0 = @(p) [p(1); p(5)]
where the dynamics are given by a non-linear state space model xdot = f(x,u,p) and x is the vector with state variables x_i, for example? Would be really nice to have this, since then I can perform my analysis. I have a work around now, but do not like this solution. My ultimate goal is to include automatic differentation for all Jacobi matrices, including the IC (!), and get a very accurate solution for the sensitivities in this way.
Thanks in advance for your help. ode, sensitivity MATLAB Answers — New Questions
Issues with Contour fill when using GRD datasets
Hi,
I’m attempting to use the GRDread2 function (grdread2 – File Exchange – MATLAB Central (mathworks.com)) to read in and then display as filled contour maps (code below).
%%%%%%%% Generate Data
load coastlines
[X,Y,Z] = grdread2(‘SD01.zmax.grd’);
grdinfo2(‘SD01.zmax.grd’);
%%%%%%%% Generate Data
hfig1 = figure % creates a graph
FW = 60; % scaling factor
set(hfig1, ‘Position’, [000 000 16 9]*FW) % sets scaling of figure [left bottom width height]
ax(1) = axes(‘position’,[0.12 0.12 0.4 0.85]) % creates an axis [left bottom width height]
hold on; box on; grid on;
set(gca,’layer’,’top’) % get current axis set frame to top
contourf(X,Y,Z,10)
ch1 = colorbar
set(ax(1),’Colormap’,jet(20))
caxis([-6 8])
ax(2) = axes(‘position’,[0.57 0.12 0.4 0.85])
hold on; box on; grid on;
set(gca,’layer’,’top’)
contourf(X,Y,Z)
contour(X,Y,Z,-1:0.5:10,’k-‘)
ch2 = colorbar;
caxis([-1 10])
cmap2 = cmocean(‘balance’);
set(ax(2),’Colormap’,cmap2)
However, while checking the output shows that the Z elevation data is present (and can be plotted with contour lines) the image only displays two colour bands (image attached). I’m relatively new to Matlab and was wondering what I’ve missed?
Many thanks,Hi,
I’m attempting to use the GRDread2 function (grdread2 – File Exchange – MATLAB Central (mathworks.com)) to read in and then display as filled contour maps (code below).
%%%%%%%% Generate Data
load coastlines
[X,Y,Z] = grdread2(‘SD01.zmax.grd’);
grdinfo2(‘SD01.zmax.grd’);
%%%%%%%% Generate Data
hfig1 = figure % creates a graph
FW = 60; % scaling factor
set(hfig1, ‘Position’, [000 000 16 9]*FW) % sets scaling of figure [left bottom width height]
ax(1) = axes(‘position’,[0.12 0.12 0.4 0.85]) % creates an axis [left bottom width height]
hold on; box on; grid on;
set(gca,’layer’,’top’) % get current axis set frame to top
contourf(X,Y,Z,10)
ch1 = colorbar
set(ax(1),’Colormap’,jet(20))
caxis([-6 8])
ax(2) = axes(‘position’,[0.57 0.12 0.4 0.85])
hold on; box on; grid on;
set(gca,’layer’,’top’)
contourf(X,Y,Z)
contour(X,Y,Z,-1:0.5:10,’k-‘)
ch2 = colorbar;
caxis([-1 10])
cmap2 = cmocean(‘balance’);
set(ax(2),’Colormap’,cmap2)
However, while checking the output shows that the Z elevation data is present (and can be plotted with contour lines) the image only displays two colour bands (image attached). I’m relatively new to Matlab and was wondering what I’ve missed?
Many thanks, Hi,
I’m attempting to use the GRDread2 function (grdread2 – File Exchange – MATLAB Central (mathworks.com)) to read in and then display as filled contour maps (code below).
%%%%%%%% Generate Data
load coastlines
[X,Y,Z] = grdread2(‘SD01.zmax.grd’);
grdinfo2(‘SD01.zmax.grd’);
%%%%%%%% Generate Data
hfig1 = figure % creates a graph
FW = 60; % scaling factor
set(hfig1, ‘Position’, [000 000 16 9]*FW) % sets scaling of figure [left bottom width height]
ax(1) = axes(‘position’,[0.12 0.12 0.4 0.85]) % creates an axis [left bottom width height]
hold on; box on; grid on;
set(gca,’layer’,’top’) % get current axis set frame to top
contourf(X,Y,Z,10)
ch1 = colorbar
set(ax(1),’Colormap’,jet(20))
caxis([-6 8])
ax(2) = axes(‘position’,[0.57 0.12 0.4 0.85])
hold on; box on; grid on;
set(gca,’layer’,’top’)
contourf(X,Y,Z)
contour(X,Y,Z,-1:0.5:10,’k-‘)
ch2 = colorbar;
caxis([-1 10])
cmap2 = cmocean(‘balance’);
set(ax(2),’Colormap’,cmap2)
However, while checking the output shows that the Z elevation data is present (and can be plotted with contour lines) the image only displays two colour bands (image attached). I’m relatively new to Matlab and was wondering what I’ve missed?
Many thanks, grd, contour MATLAB Answers — New Questions
Cumulative sum of groups
I need the cumlative sum of the second column of Data grouped by (or reset at each change in) the first column of Data please:
Data = [[1;1;1; 2;2;2; 3;3;3], [1;0;1; 0;1;1; 0;1;0]]
Answer = [Data, [1;1;2; 0;1;2; 0;1;1]]
Data =
1 1
1 0
1 1
2 0
2 1
2 1
3 0
3 1
3 0
Answer =
1 1 1
1 0 1
1 1 2
2 0 0
2 1 1
2 1 2
3 0 0
3 1 1
3 0 1I need the cumlative sum of the second column of Data grouped by (or reset at each change in) the first column of Data please:
Data = [[1;1;1; 2;2;2; 3;3;3], [1;0;1; 0;1;1; 0;1;0]]
Answer = [Data, [1;1;2; 0;1;2; 0;1;1]]
Data =
1 1
1 0
1 1
2 0
2 1
2 1
3 0
3 1
3 0
Answer =
1 1 1
1 0 1
1 1 2
2 0 0
2 1 1
2 1 2
3 0 0
3 1 1
3 0 1 I need the cumlative sum of the second column of Data grouped by (or reset at each change in) the first column of Data please:
Data = [[1;1;1; 2;2;2; 3;3;3], [1;0;1; 0;1;1; 0;1;0]]
Answer = [Data, [1;1;2; 0;1;2; 0;1;1]]
Data =
1 1
1 0
1 1
2 0
2 1
2 1
3 0
3 1
3 0
Answer =
1 1 1
1 0 1
1 1 2
2 0 0
2 1 1
2 1 2
3 0 0
3 1 1
3 0 1 cumsum, group by MATLAB Answers — New Questions
Resizing Subplots Within a Figure
Hi, I have two subplots displayed side-by-side in one figure window, as shown.
Now, the aspect ratio (width-to-height ratio) of each photo is fixed, as is the proportion of the two images in relation to one another. I’d like to make the photos larger while keeping the size of the figure window the same, but I’m running into an issue. Here’s the relevant snippet of my code:
%% DISPLAY IMAGES IN ONE FIGURE
fig = figure;
colormap(flipud(gray));
% Calculate the normalized heights based on image size
heightS = size(maxS, 1) / (size(maxS, 1) + size(maxC, 1));
heightC = size(maxC, 1) / (size(maxS, 1) + size(maxC, 1));
% Calculate the bottom position for vertical centering
bottomS = (1 – heightS) / 2;
bottomC = (1 – heightC) / 2;
% Saggital View
subplot(‘Position’, [0, bottomS, 0.5, heightS]);
imagesc(maxS);
title("Saggital View")
axis off;
axis image;
% Coronal View
subplot(‘Position’, [0.5, bottomC, 0.5, heightC]);
imagesc(maxC);
title("Coronal View")
axis off;
axis image;
set(fig, ‘Position’, [100, 100, 1000, 500]); % Set the position and size of the figure
As you can see, both subplots supposedly have a width of 0.5, meaning they each take up exactly half of the figure window. So why do the images look so small? I have no idea. I’m aware there’s additional space around the image taken up by invisble tick marks, labels, ex. but that doesn’t really explain why the images are so small. I can’t just increase their widths, because that would cause their combined width to exceed the figure size and result in the deletion of one of the subplots entirely. I need a way to make these images bigger without changing their aspect ratios, changing the size of the figure window, or changing the normalization of their values so they scale correclty with regards to one another. Does anyone have any ideas?Hi, I have two subplots displayed side-by-side in one figure window, as shown.
Now, the aspect ratio (width-to-height ratio) of each photo is fixed, as is the proportion of the two images in relation to one another. I’d like to make the photos larger while keeping the size of the figure window the same, but I’m running into an issue. Here’s the relevant snippet of my code:
%% DISPLAY IMAGES IN ONE FIGURE
fig = figure;
colormap(flipud(gray));
% Calculate the normalized heights based on image size
heightS = size(maxS, 1) / (size(maxS, 1) + size(maxC, 1));
heightC = size(maxC, 1) / (size(maxS, 1) + size(maxC, 1));
% Calculate the bottom position for vertical centering
bottomS = (1 – heightS) / 2;
bottomC = (1 – heightC) / 2;
% Saggital View
subplot(‘Position’, [0, bottomS, 0.5, heightS]);
imagesc(maxS);
title("Saggital View")
axis off;
axis image;
% Coronal View
subplot(‘Position’, [0.5, bottomC, 0.5, heightC]);
imagesc(maxC);
title("Coronal View")
axis off;
axis image;
set(fig, ‘Position’, [100, 100, 1000, 500]); % Set the position and size of the figure
As you can see, both subplots supposedly have a width of 0.5, meaning they each take up exactly half of the figure window. So why do the images look so small? I have no idea. I’m aware there’s additional space around the image taken up by invisble tick marks, labels, ex. but that doesn’t really explain why the images are so small. I can’t just increase their widths, because that would cause their combined width to exceed the figure size and result in the deletion of one of the subplots entirely. I need a way to make these images bigger without changing their aspect ratios, changing the size of the figure window, or changing the normalization of their values so they scale correclty with regards to one another. Does anyone have any ideas? Hi, I have two subplots displayed side-by-side in one figure window, as shown.
Now, the aspect ratio (width-to-height ratio) of each photo is fixed, as is the proportion of the two images in relation to one another. I’d like to make the photos larger while keeping the size of the figure window the same, but I’m running into an issue. Here’s the relevant snippet of my code:
%% DISPLAY IMAGES IN ONE FIGURE
fig = figure;
colormap(flipud(gray));
% Calculate the normalized heights based on image size
heightS = size(maxS, 1) / (size(maxS, 1) + size(maxC, 1));
heightC = size(maxC, 1) / (size(maxS, 1) + size(maxC, 1));
% Calculate the bottom position for vertical centering
bottomS = (1 – heightS) / 2;
bottomC = (1 – heightC) / 2;
% Saggital View
subplot(‘Position’, [0, bottomS, 0.5, heightS]);
imagesc(maxS);
title("Saggital View")
axis off;
axis image;
% Coronal View
subplot(‘Position’, [0.5, bottomC, 0.5, heightC]);
imagesc(maxC);
title("Coronal View")
axis off;
axis image;
set(fig, ‘Position’, [100, 100, 1000, 500]); % Set the position and size of the figure
As you can see, both subplots supposedly have a width of 0.5, meaning they each take up exactly half of the figure window. So why do the images look so small? I have no idea. I’m aware there’s additional space around the image taken up by invisble tick marks, labels, ex. but that doesn’t really explain why the images are so small. I can’t just increase their widths, because that would cause their combined width to exceed the figure size and result in the deletion of one of the subplots entirely. I need a way to make these images bigger without changing their aspect ratios, changing the size of the figure window, or changing the normalization of their values so they scale correclty with regards to one another. Does anyone have any ideas? display, figure, plot MATLAB Answers — New Questions
Is there a reason why {‘charVector’} is not considered a text scalar for argument validation purposes?
It seems like a software design inconsistency to me that this passes validation,
mustBeText({‘charVector’})
mustBeScalarOrEmpty({‘charVector’})
but this does not,
mustBeTextScalar({‘charVector’})
Is there a logic to this?It seems like a software design inconsistency to me that this passes validation,
mustBeText({‘charVector’})
mustBeScalarOrEmpty({‘charVector’})
but this does not,
mustBeTextScalar({‘charVector’})
Is there a logic to this? It seems like a software design inconsistency to me that this passes validation,
mustBeText({‘charVector’})
mustBeScalarOrEmpty({‘charVector’})
but this does not,
mustBeTextScalar({‘charVector’})
Is there a logic to this? argument validation, property validation, text scalar MATLAB Answers — New Questions