Category: Matlab
Category Archives: Matlab
What is my fault to this modelling? I want to move the model but I am not able to solve the faults.
Post Content Post Content i need help… MATLAB Answers — New Questions
Coulomb Counting with SOC Recalibration
Hello all,
Currently i am developing a Coulomb Counting method with SOC Recalibration from SOC-OCV Lookup Table. I am working with an LFP Battery. I have a Data File of the Test i conducted. So the recalibration is done only during the Rest phase of the Battery.So the procedure is that when the SOC is less than 10% or more than 90%, the SOC should be recalibrated using interpolation from the SOC-OCV table( Depending on the Step before the Rest step. If it was charging, then SOC-OCV Lookup Table in Charge direction is looked up and otherwise the the table in discharge direction.) I am encountering problems with the programme. I am attaching the script. So in the ‘recalibrateSOC’ programme, the Table is just stored with NaN, the Recalibrated SOC’s are not being updated. In the 2nd Programme where i combine Coulomb Counting with SOC Recalibration, an error is occuring in line 23. It would be of great help if someone could explain the issues and suggest actions for rectifying it.Hello all,
Currently i am developing a Coulomb Counting method with SOC Recalibration from SOC-OCV Lookup Table. I am working with an LFP Battery. I have a Data File of the Test i conducted. So the recalibration is done only during the Rest phase of the Battery.So the procedure is that when the SOC is less than 10% or more than 90%, the SOC should be recalibrated using interpolation from the SOC-OCV table( Depending on the Step before the Rest step. If it was charging, then SOC-OCV Lookup Table in Charge direction is looked up and otherwise the the table in discharge direction.) I am encountering problems with the programme. I am attaching the script. So in the ‘recalibrateSOC’ programme, the Table is just stored with NaN, the Recalibrated SOC’s are not being updated. In the 2nd Programme where i combine Coulomb Counting with SOC Recalibration, an error is occuring in line 23. It would be of great help if someone could explain the issues and suggest actions for rectifying it. Hello all,
Currently i am developing a Coulomb Counting method with SOC Recalibration from SOC-OCV Lookup Table. I am working with an LFP Battery. I have a Data File of the Test i conducted. So the recalibration is done only during the Rest phase of the Battery.So the procedure is that when the SOC is less than 10% or more than 90%, the SOC should be recalibrated using interpolation from the SOC-OCV table( Depending on the Step before the Rest step. If it was charging, then SOC-OCV Lookup Table in Charge direction is looked up and otherwise the the table in discharge direction.) I am encountering problems with the programme. I am attaching the script. So in the ‘recalibrateSOC’ programme, the Table is just stored with NaN, the Recalibrated SOC’s are not being updated. In the 2nd Programme where i combine Coulomb Counting with SOC Recalibration, an error is occuring in line 23. It would be of great help if someone could explain the issues and suggest actions for rectifying it. coulomb counting, soc estimation, matlab MATLAB Answers — New Questions
Serious Problem with FiltFilt Function
Hello everyone,
I designed a Bandpass Filter using the filterDesigner app. It is an 18th order IIR filter.
Then I export the filter both as df2sos object and "SOS and G" matrices.
Afterwards, I try filtering my data with:
y = filtfilt(Hd,x);
It gives the error: Not enough input arguments.
Well. Why don’t I use:
y = filtfilt(Hd.sosMatrix,Hd.scaleValues,x);
% or
y = filtfilt(SOS,G,x);
These do not work for my filter; they result in unstable filters. Even though my originally designed filter is stable, they give unstable results. Here is the MATLAB page for this issue.
So, how to use FiltFilt function with my df2sos object or my "SOS and G" matrices, without getting an unstable result? I’d really appreaciate some help.
Regards,
Berk
Additional Details:
Here is the code to generate my filter object:
Fstop1 = 0.0001; % First Stopband Frequency
Fpass1 = 0.0004; % First Passband Frequency
Fpass2 = 0.08; % Second Passband Frequency
Fstop2 = 0.12; % Second Stopband Frequency
Astop1 = 50; % First Stopband Attenuation (dB)
Apass = 0.5; % Passband Ripple (dB)
Astop2 = 50; % Second Stopband Attenuation (dB)
h = fdesign.bandpass(‘fst1,fp1,fp2,fst2,ast1,ap,ast2’, Fstop1, Fpass1, …
Fpass2, Fstop2, Astop1, Apass, Astop2);
Hd = designfilt(h, ‘cheby2’, …
‘MatchExactly’, ‘stopband’, …
‘SystemObject’, true);
and the screenshot from the filterDesigner app:Hello everyone,
I designed a Bandpass Filter using the filterDesigner app. It is an 18th order IIR filter.
Then I export the filter both as df2sos object and "SOS and G" matrices.
Afterwards, I try filtering my data with:
y = filtfilt(Hd,x);
It gives the error: Not enough input arguments.
Well. Why don’t I use:
y = filtfilt(Hd.sosMatrix,Hd.scaleValues,x);
% or
y = filtfilt(SOS,G,x);
These do not work for my filter; they result in unstable filters. Even though my originally designed filter is stable, they give unstable results. Here is the MATLAB page for this issue.
So, how to use FiltFilt function with my df2sos object or my "SOS and G" matrices, without getting an unstable result? I’d really appreaciate some help.
Regards,
Berk
Additional Details:
Here is the code to generate my filter object:
Fstop1 = 0.0001; % First Stopband Frequency
Fpass1 = 0.0004; % First Passband Frequency
Fpass2 = 0.08; % Second Passband Frequency
Fstop2 = 0.12; % Second Stopband Frequency
Astop1 = 50; % First Stopband Attenuation (dB)
Apass = 0.5; % Passband Ripple (dB)
Astop2 = 50; % Second Stopband Attenuation (dB)
h = fdesign.bandpass(‘fst1,fp1,fp2,fst2,ast1,ap,ast2’, Fstop1, Fpass1, …
Fpass2, Fstop2, Astop1, Apass, Astop2);
Hd = designfilt(h, ‘cheby2’, …
‘MatchExactly’, ‘stopband’, …
‘SystemObject’, true);
and the screenshot from the filterDesigner app: Hello everyone,
I designed a Bandpass Filter using the filterDesigner app. It is an 18th order IIR filter.
Then I export the filter both as df2sos object and "SOS and G" matrices.
Afterwards, I try filtering my data with:
y = filtfilt(Hd,x);
It gives the error: Not enough input arguments.
Well. Why don’t I use:
y = filtfilt(Hd.sosMatrix,Hd.scaleValues,x);
% or
y = filtfilt(SOS,G,x);
These do not work for my filter; they result in unstable filters. Even though my originally designed filter is stable, they give unstable results. Here is the MATLAB page for this issue.
So, how to use FiltFilt function with my df2sos object or my "SOS and G" matrices, without getting an unstable result? I’d really appreaciate some help.
Regards,
Berk
Additional Details:
Here is the code to generate my filter object:
Fstop1 = 0.0001; % First Stopband Frequency
Fpass1 = 0.0004; % First Passband Frequency
Fpass2 = 0.08; % Second Passband Frequency
Fstop2 = 0.12; % Second Stopband Frequency
Astop1 = 50; % First Stopband Attenuation (dB)
Apass = 0.5; % Passband Ripple (dB)
Astop2 = 50; % Second Stopband Attenuation (dB)
h = fdesign.bandpass(‘fst1,fp1,fp2,fst2,ast1,ap,ast2’, Fstop1, Fpass1, …
Fpass2, Fstop2, Astop1, Apass, Astop2);
Hd = designfilt(h, ‘cheby2’, …
‘MatchExactly’, ‘stopband’, …
‘SystemObject’, true);
and the screenshot from the filterDesigner app: filterdesigner, signalprocessingtoolbox, filtfilt, filter, unstable, df2sos, iir filter, sos g MATLAB Answers — New Questions
Can FILTFILT(B, A, X) yeild the same results as FILTFILT(SOS, G, X) assuming inputs are generated via [z,p,k] = butter(3,Wn) + [sos,g] = zp2sos(z,p,k) and [A,B] = butter(3,Wn)
Hi all,
I am working on a signal processing and bandpass filtering problem which uses a butterworth filter. I was recently advised to try using the [zero, pole, gain] output instead of the [A,B] output (this output returns the filter coefficients in length N+1 vectors B (numerator) and A (denominator)) for increased reliability between matlab versions.
I do not understand the nuances of these different methods. I am getting different result (tradfilt, h_signal, thephase) with each method and want to understand why.
Method 1 Code
Wn = [Fpass(1,1)/(Fs/2) Fpass(1,2)/(Fs/2)]; % normalized by the nyquist frequency
[B,A]= butter(3,Wn)
tradfilt = filtfilt(B,A,signal);
h_signal=hilbert(tradfilt);
thephase=atan2(tradfilt, imag(h_signal));
Method 2 code
Wn = [Fpass(1,1)/(Fs/2) Fpass(1,2)/(Fs/2)]; % normalized by the nyquist frequency
[z,p,k] = butter(3,Wn);
[sos,g] = zp2sos(z,p,k);
tradfilt= filtfilt(sos,g,signal);
h_signal=hilbert(tradfilt);
thephase=atan2(tradfilt, imag(h_signal));
Thanks!Hi all,
I am working on a signal processing and bandpass filtering problem which uses a butterworth filter. I was recently advised to try using the [zero, pole, gain] output instead of the [A,B] output (this output returns the filter coefficients in length N+1 vectors B (numerator) and A (denominator)) for increased reliability between matlab versions.
I do not understand the nuances of these different methods. I am getting different result (tradfilt, h_signal, thephase) with each method and want to understand why.
Method 1 Code
Wn = [Fpass(1,1)/(Fs/2) Fpass(1,2)/(Fs/2)]; % normalized by the nyquist frequency
[B,A]= butter(3,Wn)
tradfilt = filtfilt(B,A,signal);
h_signal=hilbert(tradfilt);
thephase=atan2(tradfilt, imag(h_signal));
Method 2 code
Wn = [Fpass(1,1)/(Fs/2) Fpass(1,2)/(Fs/2)]; % normalized by the nyquist frequency
[z,p,k] = butter(3,Wn);
[sos,g] = zp2sos(z,p,k);
tradfilt= filtfilt(sos,g,signal);
h_signal=hilbert(tradfilt);
thephase=atan2(tradfilt, imag(h_signal));
Thanks! Hi all,
I am working on a signal processing and bandpass filtering problem which uses a butterworth filter. I was recently advised to try using the [zero, pole, gain] output instead of the [A,B] output (this output returns the filter coefficients in length N+1 vectors B (numerator) and A (denominator)) for increased reliability between matlab versions.
I do not understand the nuances of these different methods. I am getting different result (tradfilt, h_signal, thephase) with each method and want to understand why.
Method 1 Code
Wn = [Fpass(1,1)/(Fs/2) Fpass(1,2)/(Fs/2)]; % normalized by the nyquist frequency
[B,A]= butter(3,Wn)
tradfilt = filtfilt(B,A,signal);
h_signal=hilbert(tradfilt);
thephase=atan2(tradfilt, imag(h_signal));
Method 2 code
Wn = [Fpass(1,1)/(Fs/2) Fpass(1,2)/(Fs/2)]; % normalized by the nyquist frequency
[z,p,k] = butter(3,Wn);
[sos,g] = zp2sos(z,p,k);
tradfilt= filtfilt(sos,g,signal);
h_signal=hilbert(tradfilt);
thephase=atan2(tradfilt, imag(h_signal));
Thanks! signal processing, butter, filtfilt, zp2sos, hilbert, gain, pole, zero MATLAB Answers — New Questions
Coordinate System Mismatch When Importing Robot Model from SolidWorks 2021 to MATLAB 2023b Simscape
Hi everyone,
I am working on a robot model in SolidWorks 2021 and have exported it to MATLAB 2023b for simulation in Simscape. However, I encountered an issue where the coordinate system of my robot seems to be flipped or mismatched compared to the one I set up in SolidWorks. Specifically, the Z-axis appears to be inverted in MATLAB.
Here are some details about my setup:
I used the Simscape Multibody Link plugin to export the SolidWorks model.
The transform settings in MATLAB use an arbitrary axis rotation and Cartesian translation, as exported.
I have verified the axis and angle values, but the coordinate system doesn’t match the original SolidWorks model.
My questions are:
How can I ensure that the coordinate systems in MATLAB/Simscape exactly match those in SolidWorks?
Are there specific settings during the export or import process that I need to check to avoid this mismatch?
If the coordinate system is flipped, what adjustments should I make in MATLAB to correct it without breaking the simulation?
Any guidance or tips would be greatly appreciated! Thank you in advance.Hi everyone,
I am working on a robot model in SolidWorks 2021 and have exported it to MATLAB 2023b for simulation in Simscape. However, I encountered an issue where the coordinate system of my robot seems to be flipped or mismatched compared to the one I set up in SolidWorks. Specifically, the Z-axis appears to be inverted in MATLAB.
Here are some details about my setup:
I used the Simscape Multibody Link plugin to export the SolidWorks model.
The transform settings in MATLAB use an arbitrary axis rotation and Cartesian translation, as exported.
I have verified the axis and angle values, but the coordinate system doesn’t match the original SolidWorks model.
My questions are:
How can I ensure that the coordinate systems in MATLAB/Simscape exactly match those in SolidWorks?
Are there specific settings during the export or import process that I need to check to avoid this mismatch?
If the coordinate system is flipped, what adjustments should I make in MATLAB to correct it without breaking the simulation?
Any guidance or tips would be greatly appreciated! Thank you in advance. Hi everyone,
I am working on a robot model in SolidWorks 2021 and have exported it to MATLAB 2023b for simulation in Simscape. However, I encountered an issue where the coordinate system of my robot seems to be flipped or mismatched compared to the one I set up in SolidWorks. Specifically, the Z-axis appears to be inverted in MATLAB.
Here are some details about my setup:
I used the Simscape Multibody Link plugin to export the SolidWorks model.
The transform settings in MATLAB use an arbitrary axis rotation and Cartesian translation, as exported.
I have verified the axis and angle values, but the coordinate system doesn’t match the original SolidWorks model.
My questions are:
How can I ensure that the coordinate systems in MATLAB/Simscape exactly match those in SolidWorks?
Are there specific settings during the export or import process that I need to check to avoid this mismatch?
If the coordinate system is flipped, what adjustments should I make in MATLAB to correct it without breaking the simulation?
Any guidance or tips would be greatly appreciated! Thank you in advance. simscape, solidworks, multibody, coordinate-system, model MATLAB Answers — New Questions
Implementing Process Control for Heat Exchanger Networks in MATLAB
Hello everyone,
I am currently working on a project involving real-time process control for Heat Exchanger Networks (HENs) and would like to implement control strategies using MATLAB. Specifically, my goal is to develop a model that can effectively reject disturbances in temperature and flow rate heat capacity in real-time.
Here are the main aspects of my query:
Dynamic modeling: What is the best approach to dynamically model a heat exchanger network in MATLAB to account for temperature and flow variations? Should I use Simulink, MATLAB scripts, or a combination of both?
Control strategies: Are there any resources or examples for implementing adaptive control or model predictive control (MPC) in HENs? I aim to handle fluctuations in inlet temperatures and flow rates effectively.
Real-time simulation: What methods or toolboxes in MATLAB are recommended for real-time simulation and testing of control strategies for HENs?
If anyone has worked on similar problems or has suggestions, I would appreciate guidance, references, or sample code to kickstart this process.
Thank you in advance for your support!Hello everyone,
I am currently working on a project involving real-time process control for Heat Exchanger Networks (HENs) and would like to implement control strategies using MATLAB. Specifically, my goal is to develop a model that can effectively reject disturbances in temperature and flow rate heat capacity in real-time.
Here are the main aspects of my query:
Dynamic modeling: What is the best approach to dynamically model a heat exchanger network in MATLAB to account for temperature and flow variations? Should I use Simulink, MATLAB scripts, or a combination of both?
Control strategies: Are there any resources or examples for implementing adaptive control or model predictive control (MPC) in HENs? I aim to handle fluctuations in inlet temperatures and flow rates effectively.
Real-time simulation: What methods or toolboxes in MATLAB are recommended for real-time simulation and testing of control strategies for HENs?
If anyone has worked on similar problems or has suggestions, I would appreciate guidance, references, or sample code to kickstart this process.
Thank you in advance for your support! Hello everyone,
I am currently working on a project involving real-time process control for Heat Exchanger Networks (HENs) and would like to implement control strategies using MATLAB. Specifically, my goal is to develop a model that can effectively reject disturbances in temperature and flow rate heat capacity in real-time.
Here are the main aspects of my query:
Dynamic modeling: What is the best approach to dynamically model a heat exchanger network in MATLAB to account for temperature and flow variations? Should I use Simulink, MATLAB scripts, or a combination of both?
Control strategies: Are there any resources or examples for implementing adaptive control or model predictive control (MPC) in HENs? I aim to handle fluctuations in inlet temperatures and flow rates effectively.
Real-time simulation: What methods or toolboxes in MATLAB are recommended for real-time simulation and testing of control strategies for HENs?
If anyone has worked on similar problems or has suggestions, I would appreciate guidance, references, or sample code to kickstart this process.
Thank you in advance for your support! matlab, simulink, heat exchanger network, process control, dynamic modeling, adaptive control, model predictive control, real-time simulation, temperature control, flow rate control, disturbance rejection, energy systems, control system MATLAB Answers — New Questions
How to model a piston with a retracting spring at one end and having single hydraulic port??
The spring is to exert some force on the fluid inside the cyinder, thus pressurizing it. I want to find out the response rate (outlet flowrate) of the fluid when pushed out by the spring with different stiffness rates? Can anyone help? How to model this block in SimHydraulics?The spring is to exert some force on the fluid inside the cyinder, thus pressurizing it. I want to find out the response rate (outlet flowrate) of the fluid when pushed out by the spring with different stiffness rates? Can anyone help? How to model this block in SimHydraulics? The spring is to exert some force on the fluid inside the cyinder, thus pressurizing it. I want to find out the response rate (outlet flowrate) of the fluid when pushed out by the spring with different stiffness rates? Can anyone help? How to model this block in SimHydraulics? simhydraulics, simulink, matlab MATLAB Answers — New Questions
Why do I receive an Error 348 when attempting to activate my MATLAB license?
When trying to activate my license, I receive the error message:
ERROR: A Licensed End User is already linked with this license. Please contact your license administrator for assistance.
How do I activate this license?When trying to activate my license, I receive the error message:
ERROR: A Licensed End User is already linked with this license. Please contact your license administrator for assistance.
How do I activate this license? When trying to activate my license, I receive the error message:
ERROR: A Licensed End User is already linked with this license. Please contact your license administrator for assistance.
How do I activate this license? MATLAB Answers — New Questions
Add variable vectors to NMDS plot which visualizes observations.
I’m not sure how to add vectors that visualize the effect of data set parameters to an NMDS plot.
Using the example provided by matlab for function mdscale (shown below), I can create the figure with points for each observation (i.e. cerials of a certain brand). How would I go about adding vectors to the plot for each of the parameters included in the analysis, where the length of the vector indicates the strength of effect on the ordination. For the cerial example, these vectors would represent calories, protien, fat, sodium, fiber, carbo, sugars, shelf, potass, and vitamins. If you could show my how to do this in the sample below, that would be really helpful!
load cereal.mat
X = [Calories Protein Fat Sodium Fiber …
Carbo Sugars Shelf Potass Vitamins];
% Take a subset from a single manufacturer
mfg1 = strcmp(‘G’,cellstr(Mfg));
X = X(mfg1,:);
dissimilarities = pdist(zscore(X),’cityblock’);
[Y,stress] =…
mdscale(dissimilarities,2,’criterion’,’stress’);
plot(Y(:,1),Y(:,2),’o’,’LineWidth’,2);
gname(Name(mfg1))I’m not sure how to add vectors that visualize the effect of data set parameters to an NMDS plot.
Using the example provided by matlab for function mdscale (shown below), I can create the figure with points for each observation (i.e. cerials of a certain brand). How would I go about adding vectors to the plot for each of the parameters included in the analysis, where the length of the vector indicates the strength of effect on the ordination. For the cerial example, these vectors would represent calories, protien, fat, sodium, fiber, carbo, sugars, shelf, potass, and vitamins. If you could show my how to do this in the sample below, that would be really helpful!
load cereal.mat
X = [Calories Protein Fat Sodium Fiber …
Carbo Sugars Shelf Potass Vitamins];
% Take a subset from a single manufacturer
mfg1 = strcmp(‘G’,cellstr(Mfg));
X = X(mfg1,:);
dissimilarities = pdist(zscore(X),’cityblock’);
[Y,stress] =…
mdscale(dissimilarities,2,’criterion’,’stress’);
plot(Y(:,1),Y(:,2),’o’,’LineWidth’,2);
gname(Name(mfg1)) I’m not sure how to add vectors that visualize the effect of data set parameters to an NMDS plot.
Using the example provided by matlab for function mdscale (shown below), I can create the figure with points for each observation (i.e. cerials of a certain brand). How would I go about adding vectors to the plot for each of the parameters included in the analysis, where the length of the vector indicates the strength of effect on the ordination. For the cerial example, these vectors would represent calories, protien, fat, sodium, fiber, carbo, sugars, shelf, potass, and vitamins. If you could show my how to do this in the sample below, that would be really helpful!
load cereal.mat
X = [Calories Protein Fat Sodium Fiber …
Carbo Sugars Shelf Potass Vitamins];
% Take a subset from a single manufacturer
mfg1 = strcmp(‘G’,cellstr(Mfg));
X = X(mfg1,:);
dissimilarities = pdist(zscore(X),’cityblock’);
[Y,stress] =…
mdscale(dissimilarities,2,’criterion’,’stress’);
plot(Y(:,1),Y(:,2),’o’,’LineWidth’,2);
gname(Name(mfg1)) nmds MATLAB Answers — New Questions
Passing a data file to a function in parfor or parfeval
I want to pass a data file to process in parallel. Same data file to be used by each worker for complete process and each worker should process the whole datafile.I want to pass a data file to process in parallel. Same data file to be used by each worker for complete process and each worker should process the whole datafile. I want to pass a data file to process in parallel. Same data file to be used by each worker for complete process and each worker should process the whole datafile. parfor, parfeval, datafile MATLAB Answers — New Questions
Use of Simscape to simulate solid material flowing from a container to another container
On simscape Multibody, I would like to simulate solid material (i.e. solid fertilizer) flowing from a container to another container, initially by gravity. Any ideas how can I do this? I could not find a way to model this material. Initially I tough about modeling hundreds of spheres with spatial block contacts, but not sure if this is possible or maybe another approach.On simscape Multibody, I would like to simulate solid material (i.e. solid fertilizer) flowing from a container to another container, initially by gravity. Any ideas how can I do this? I could not find a way to model this material. Initially I tough about modeling hundreds of spheres with spatial block contacts, but not sure if this is possible or maybe another approach. On simscape Multibody, I would like to simulate solid material (i.e. solid fertilizer) flowing from a container to another container, initially by gravity. Any ideas how can I do this? I could not find a way to model this material. Initially I tough about modeling hundreds of spheres with spatial block contacts, but not sure if this is possible or maybe another approach. simscape multibody MATLAB Answers — New Questions
How to get correct pixel size in 2D after cut 3D voxel using obliqueslice
Hi,
I have a 3D voxel created from a CT scanner. I cut it with obliqueslice to get the surface that I would like to calculate. As the cut was not orthogonal cut I guess my pixel size in space changed. There is a way to correct it? I think I should calculate the angle between each axis and apply it to each pixels (x, y,z)? Is it correct way to do it? Thank you for any respons.Hi,
I have a 3D voxel created from a CT scanner. I cut it with obliqueslice to get the surface that I would like to calculate. As the cut was not orthogonal cut I guess my pixel size in space changed. There is a way to correct it? I think I should calculate the angle between each axis and apply it to each pixels (x, y,z)? Is it correct way to do it? Thank you for any respons. Hi,
I have a 3D voxel created from a CT scanner. I cut it with obliqueslice to get the surface that I would like to calculate. As the cut was not orthogonal cut I guess my pixel size in space changed. There is a way to correct it? I think I should calculate the angle between each axis and apply it to each pixels (x, y,z)? Is it correct way to do it? Thank you for any respons. obliqueslice, matlab, image processing MATLAB Answers — New Questions
How to extract cell array of 2D matrices into a timeseries?
I have some data that is stored as a 1666×1 cell array. Each cell contains a 4×19 double. I need to extract this data and attach it to a timeseries object. Timeseries will not take a cell array directly, so I need to extract the cells.
So let’s say the cell array is named data, and the timeseries is ts. I need:
ts.Data(1) = data{1}
ts.Data(2) = data{2}
etc.
cell2mat() concatenates everything into 6664×19, and I can’t get reshape() to chop it up into the correct 4×19 blocks. I could do it in a for loop, but that’s not very satisfying in MATLAB.
I know this is a simple syntax thing, but I can’t seem to find an answer that works.I have some data that is stored as a 1666×1 cell array. Each cell contains a 4×19 double. I need to extract this data and attach it to a timeseries object. Timeseries will not take a cell array directly, so I need to extract the cells.
So let’s say the cell array is named data, and the timeseries is ts. I need:
ts.Data(1) = data{1}
ts.Data(2) = data{2}
etc.
cell2mat() concatenates everything into 6664×19, and I can’t get reshape() to chop it up into the correct 4×19 blocks. I could do it in a for loop, but that’s not very satisfying in MATLAB.
I know this is a simple syntax thing, but I can’t seem to find an answer that works. I have some data that is stored as a 1666×1 cell array. Each cell contains a 4×19 double. I need to extract this data and attach it to a timeseries object. Timeseries will not take a cell array directly, so I need to extract the cells.
So let’s say the cell array is named data, and the timeseries is ts. I need:
ts.Data(1) = data{1}
ts.Data(2) = data{2}
etc.
cell2mat() concatenates everything into 6664×19, and I can’t get reshape() to chop it up into the correct 4×19 blocks. I could do it in a for loop, but that’s not very satisfying in MATLAB.
I know this is a simple syntax thing, but I can’t seem to find an answer that works. timeseries, matrix, cell MATLAB Answers — New Questions
MATLAB GUI displays black with XQuartz
I am running MATLAB R2021a from a remote Linux server. I am able to bring up the GUI on my local macbook running macOS 12.1 using XQuartz and ssh, but the GUI usually displays black where the white usually is. Sometimes the window displays in the right color, (white) but only for a few seconds, then reverts back to the black. When it’s black, I can still see the GUI, it’s just very hard to read.I am running MATLAB R2021a from a remote Linux server. I am able to bring up the GUI on my local macbook running macOS 12.1 using XQuartz and ssh, but the GUI usually displays black where the white usually is. Sometimes the window displays in the right color, (white) but only for a few seconds, then reverts back to the black. When it’s black, I can still see the GUI, it’s just very hard to read. I am running MATLAB R2021a from a remote Linux server. I am able to bring up the GUI on my local macbook running macOS 12.1 using XQuartz and ssh, but the GUI usually displays black where the white usually is. Sometimes the window displays in the right color, (white) but only for a few seconds, then reverts back to the black. When it’s black, I can still see the GUI, it’s just very hard to read. gui, xquartz, x11 MATLAB Answers — New Questions
Rocket release time error
Hello,
I made a previous post about a rocket simulation project I have. I am still stuck on the same project, but I managed to solve some of the problems. The current issue is some errors I get when I run problem c). My theory, after some debuging is that the issue is somwhere between row 260 and 271. Can anyone explain what these errors are from and how I can fix them?
Enter which problem ao run, a, c or d, enter problem: c
268 elseif tu<params_mini(3)
Index exceeds the number of array elements. Index must not exceed 4.
Error in testador>@(vx)(problem_main(5)*cosd(problem_param(5))-problem_main(4)*vx*V)/total_mass (line 311)
dvxdt = @(vx) (problem_main(5) * cosd(problem_param(5)) – problem_main(4) * vx * V) / total_mass;
Error in testador>Rungekutta (line 318)
k1vx = dvxdt(problem_param(3)); k1vy = dvydt(problem_param(4));
Error in testador>trajectory (line 269)
params = Rungekutta(params, user_inp, access_keys, dt_unrefined); % Runs mini rocket
Error in testador (line 32)
Height_distance = trajectory(params, user_inp, access_keys); % Pass params.c to rungekuttaHello,
I made a previous post about a rocket simulation project I have. I am still stuck on the same project, but I managed to solve some of the problems. The current issue is some errors I get when I run problem c). My theory, after some debuging is that the issue is somwhere between row 260 and 271. Can anyone explain what these errors are from and how I can fix them?
Enter which problem ao run, a, c or d, enter problem: c
268 elseif tu<params_mini(3)
Index exceeds the number of array elements. Index must not exceed 4.
Error in testador>@(vx)(problem_main(5)*cosd(problem_param(5))-problem_main(4)*vx*V)/total_mass (line 311)
dvxdt = @(vx) (problem_main(5) * cosd(problem_param(5)) – problem_main(4) * vx * V) / total_mass;
Error in testador>Rungekutta (line 318)
k1vx = dvxdt(problem_param(3)); k1vy = dvydt(problem_param(4));
Error in testador>trajectory (line 269)
params = Rungekutta(params, user_inp, access_keys, dt_unrefined); % Runs mini rocket
Error in testador (line 32)
Height_distance = trajectory(params, user_inp, access_keys); % Pass params.c to rungekutta Hello,
I made a previous post about a rocket simulation project I have. I am still stuck on the same project, but I managed to solve some of the problems. The current issue is some errors I get when I run problem c). My theory, after some debuging is that the issue is somwhere between row 260 and 271. Can anyone explain what these errors are from and how I can fix them?
Enter which problem ao run, a, c or d, enter problem: c
268 elseif tu<params_mini(3)
Index exceeds the number of array elements. Index must not exceed 4.
Error in testador>@(vx)(problem_main(5)*cosd(problem_param(5))-problem_main(4)*vx*V)/total_mass (line 311)
dvxdt = @(vx) (problem_main(5) * cosd(problem_param(5)) – problem_main(4) * vx * V) / total_mass;
Error in testador>Rungekutta (line 318)
k1vx = dvxdt(problem_param(3)); k1vy = dvydt(problem_param(4));
Error in testador>trajectory (line 269)
params = Rungekutta(params, user_inp, access_keys, dt_unrefined); % Runs mini rocket
Error in testador (line 32)
Height_distance = trajectory(params, user_inp, access_keys); % Pass params.c to rungekutta trajectory, matlab, differential equations MATLAB Answers — New Questions
implementing the EM algorithm with a Kalman filter and smoother
I am looking for a sample MATLAB code that implements the EM algorithm with a Kalman filter and smoother. If anyone could assist, I would greatly appreciate it. Thank you in advance!I am looking for a sample MATLAB code that implements the EM algorithm with a Kalman filter and smoother. If anyone could assist, I would greatly appreciate it. Thank you in advance! I am looking for a sample MATLAB code that implements the EM algorithm with a Kalman filter and smoother. If anyone could assist, I would greatly appreciate it. Thank you in advance! emklf MATLAB Answers — New Questions
Using data cursor with pcolor
If one uses the data cursor on a pcolor plot, you will see three coordinates, X, Y, and Z, but the Z coordinate is always zero. It took me some time to realize that pcolor is simply a variant of the surface function, with the view fixed from above (normal to the xy plane). Inspection of the data associated with the pcolor handle will show that the "Z" values are actually stored in the CData array, and the ZData array is otherwise set to zero. This is a clever arrangement in that plot is fixed at Z = 0, and the Z values are otherwise rendered as scaled colors. The downside is that this arrangement cripples the datacursor (i.e. the Z value is not correctly reported).
One solution is to set ZData = CData (see Figure 2 produced by the code below). The datacursor will now show local Z values. The downside is that pcolor surface is now fully 3D. As a consequence, other plot elements (contours, points, lines) may be masked by this 3D surface. You can see the 3D "pcolor" surface in figure 2 by rotating the plot or by running the command "view(3)" in the command window.
The simpliest "fix" would be to add "C" values to the datacursor. (Perhaps I should suggest this as a new feature.) You will find that if you click on the contour lines, that the datacursor reports back with a variable "Level", so this kind of fix is possible. Or I could write a custom modifcation to the datacursor.
My hope is that someone out there may have found a simplier fix.
Best,
Mark
% Create data
[X,Y] = meshgrid(-2:0.2:2,-2:0.2:2);
Z = X.*exp(-X.^2 – Y.^2);
% Pcolor plot without modification. Datacursor will show Z = 0. Superimposed contours work okay.
figure(1)
hold on
hP = pcolor(X,Y,Z); shading interp;
contour(X,Y,Z, ‘Color’, ‘k’, ‘LineWidth’, 1);
datacursormode on
% PColor plot with modification (ZData = CData), Z value in data cursor works, but contours are locally masked.
figure(2)
hold on
hP = pcolor(X,Y,Z); shading interp;
hP.ZData = hP.CData;
contour(X,Y,Z, ‘Color’, ‘k’, ‘LineWidth’, 1);
datacursormode onIf one uses the data cursor on a pcolor plot, you will see three coordinates, X, Y, and Z, but the Z coordinate is always zero. It took me some time to realize that pcolor is simply a variant of the surface function, with the view fixed from above (normal to the xy plane). Inspection of the data associated with the pcolor handle will show that the "Z" values are actually stored in the CData array, and the ZData array is otherwise set to zero. This is a clever arrangement in that plot is fixed at Z = 0, and the Z values are otherwise rendered as scaled colors. The downside is that this arrangement cripples the datacursor (i.e. the Z value is not correctly reported).
One solution is to set ZData = CData (see Figure 2 produced by the code below). The datacursor will now show local Z values. The downside is that pcolor surface is now fully 3D. As a consequence, other plot elements (contours, points, lines) may be masked by this 3D surface. You can see the 3D "pcolor" surface in figure 2 by rotating the plot or by running the command "view(3)" in the command window.
The simpliest "fix" would be to add "C" values to the datacursor. (Perhaps I should suggest this as a new feature.) You will find that if you click on the contour lines, that the datacursor reports back with a variable "Level", so this kind of fix is possible. Or I could write a custom modifcation to the datacursor.
My hope is that someone out there may have found a simplier fix.
Best,
Mark
% Create data
[X,Y] = meshgrid(-2:0.2:2,-2:0.2:2);
Z = X.*exp(-X.^2 – Y.^2);
% Pcolor plot without modification. Datacursor will show Z = 0. Superimposed contours work okay.
figure(1)
hold on
hP = pcolor(X,Y,Z); shading interp;
contour(X,Y,Z, ‘Color’, ‘k’, ‘LineWidth’, 1);
datacursormode on
% PColor plot with modification (ZData = CData), Z value in data cursor works, but contours are locally masked.
figure(2)
hold on
hP = pcolor(X,Y,Z); shading interp;
hP.ZData = hP.CData;
contour(X,Y,Z, ‘Color’, ‘k’, ‘LineWidth’, 1);
datacursormode on If one uses the data cursor on a pcolor plot, you will see three coordinates, X, Y, and Z, but the Z coordinate is always zero. It took me some time to realize that pcolor is simply a variant of the surface function, with the view fixed from above (normal to the xy plane). Inspection of the data associated with the pcolor handle will show that the "Z" values are actually stored in the CData array, and the ZData array is otherwise set to zero. This is a clever arrangement in that plot is fixed at Z = 0, and the Z values are otherwise rendered as scaled colors. The downside is that this arrangement cripples the datacursor (i.e. the Z value is not correctly reported).
One solution is to set ZData = CData (see Figure 2 produced by the code below). The datacursor will now show local Z values. The downside is that pcolor surface is now fully 3D. As a consequence, other plot elements (contours, points, lines) may be masked by this 3D surface. You can see the 3D "pcolor" surface in figure 2 by rotating the plot or by running the command "view(3)" in the command window.
The simpliest "fix" would be to add "C" values to the datacursor. (Perhaps I should suggest this as a new feature.) You will find that if you click on the contour lines, that the datacursor reports back with a variable "Level", so this kind of fix is possible. Or I could write a custom modifcation to the datacursor.
My hope is that someone out there may have found a simplier fix.
Best,
Mark
% Create data
[X,Y] = meshgrid(-2:0.2:2,-2:0.2:2);
Z = X.*exp(-X.^2 – Y.^2);
% Pcolor plot without modification. Datacursor will show Z = 0. Superimposed contours work okay.
figure(1)
hold on
hP = pcolor(X,Y,Z); shading interp;
contour(X,Y,Z, ‘Color’, ‘k’, ‘LineWidth’, 1);
datacursormode on
% PColor plot with modification (ZData = CData), Z value in data cursor works, but contours are locally masked.
figure(2)
hold on
hP = pcolor(X,Y,Z); shading interp;
hP.ZData = hP.CData;
contour(X,Y,Z, ‘Color’, ‘k’, ‘LineWidth’, 1);
datacursormode on pcolor, datacursor, surface MATLAB Answers — New Questions
I need answers can you please answer
Post Content Post Content electric_motor_control MATLAB Answers — New Questions
How do you write to excel a cell array that contains both strings and numbers?
I have to write a relatively large cell array to excel. The text is primarily column headers but the data does have some text intertwined in it. Is there a simple way to do this?
I’ve done some digging but most everything I’ve found says use _fprintf_ and specify when data is of a specific type. This data is too large to run something like that.
The text data is in specific columns, if there were a way to identify text data as strings and just tell MATLAB that all other fields are numeric, that’s viable.I have to write a relatively large cell array to excel. The text is primarily column headers but the data does have some text intertwined in it. Is there a simple way to do this?
I’ve done some digging but most everything I’ve found says use _fprintf_ and specify when data is of a specific type. This data is too large to run something like that.
The text data is in specific columns, if there were a way to identify text data as strings and just tell MATLAB that all other fields are numeric, that’s viable. I have to write a relatively large cell array to excel. The text is primarily column headers but the data does have some text intertwined in it. Is there a simple way to do this?
I’ve done some digging but most everything I’ve found says use _fprintf_ and specify when data is of a specific type. This data is too large to run something like that.
The text data is in specific columns, if there were a way to identify text data as strings and just tell MATLAB that all other fields are numeric, that’s viable. xlswrite, fprintf, csvwrite MATLAB Answers — New Questions
that code does not work well and every time give the same number 5 times every time and not indexd to be used in an another place thank you
no=5;
x=zeros(no,1);
for i=1:no
waitfor(app.refindexEditField,’value’);
x(i)=app.refindexEditField.Value;
end
app.refindexEditField.Value=inf;
fprintf(‘ %.1f n ‘,x)
plot(app.UIAxes,(1:no)’,x(1:i),’-r’)no=5;
x=zeros(no,1);
for i=1:no
waitfor(app.refindexEditField,’value’);
x(i)=app.refindexEditField.Value;
end
app.refindexEditField.Value=inf;
fprintf(‘ %.1f n ‘,x)
plot(app.UIAxes,(1:no)’,x(1:i),’-r’) no=5;
x=zeros(no,1);
for i=1:no
waitfor(app.refindexEditField,’value’);
x(i)=app.refindexEditField.Value;
end
app.refindexEditField.Value=inf;
fprintf(‘ %.1f n ‘,x)
plot(app.UIAxes,(1:no)’,x(1:i),’-r’) app designer, matlab 2021a MATLAB Answers — New Questions