Month: January 2025
Issues with tables and writetable from data passed from uitable
Hello, I have an array in a uitable that I want to save to a csv file as well as the column headings. It seems out of the write options available (writecell,writematrix, writetable) – it is only writetable that allows this
Writetable appears to work, but when I open the CSV file it hasn’t and I can’t understand why
This is my code:
T=app.UITable;
data=T.Data;
C=array2table(data); % Create table format
T.ColumnName
C.Properties.VariableNames=T.ColumnName;
C.Properties.Description=’Scan Profile’;
C = addprop(C,{‘ScanStart’,’ScanTime’},{‘table’,’table’});
C.Properties.CustomProperties.ScanStart = app.scannow;
C.Properties.CustomProperties.ScanTime = app.scantime;
C.Properties
% C.Properties.VariableNames
writetable(C,savepath);
ReportMessage(app,’ Data Saved Using Writetable’);
And in the command window I get this, indicating all is O.K
ans =
6×1 cell array
{‘Idx’ }
{‘YPos(mm)’}
{‘Sep1’ }
{‘Sep2’ }
{‘<Sep>’ }
{‘dpixel’ }
ans =
TableProperties with properties:
Description: ‘Surface Profile’
UserData: []
DimensionNames: {‘Row’ ‘Variables’}
VariableNames: {‘Idx’ ‘YPos(mm)’ ‘Sep1’ ‘Sep2’ ‘<Sep>’ ‘dpixel’}
VariableDescriptions: {}
VariableUnits: {}
VariableContinuity: []
RowNames: {}
Custom Properties (access using t.Properties.CustomProperties.<name>):
ScanStart: "29-Jan-2025 09:41:35"
ScanTime: ‘174.2796’
But then the file looks like this:
So no headings.
And When i also try to load via readtable – all of the description and custom propeerrties are not present
ans =
TableProperties with properties:
Description: ”
UserData: []
DimensionNames: {‘Row’ ‘Variables’}
VariableNames: {‘Var1’ ‘Var2’ ‘Var3’ ‘Var4’ ‘Var5’ ‘Var6’}
VariableDescriptions: {}
VariableUnits: {}
VariableContinuity: []
RowNames: {}
CustomProperties: No custom properties are set.
Use addprop and rmprop to modify CustomProperties.Hello, I have an array in a uitable that I want to save to a csv file as well as the column headings. It seems out of the write options available (writecell,writematrix, writetable) – it is only writetable that allows this
Writetable appears to work, but when I open the CSV file it hasn’t and I can’t understand why
This is my code:
T=app.UITable;
data=T.Data;
C=array2table(data); % Create table format
T.ColumnName
C.Properties.VariableNames=T.ColumnName;
C.Properties.Description=’Scan Profile’;
C = addprop(C,{‘ScanStart’,’ScanTime’},{‘table’,’table’});
C.Properties.CustomProperties.ScanStart = app.scannow;
C.Properties.CustomProperties.ScanTime = app.scantime;
C.Properties
% C.Properties.VariableNames
writetable(C,savepath);
ReportMessage(app,’ Data Saved Using Writetable’);
And in the command window I get this, indicating all is O.K
ans =
6×1 cell array
{‘Idx’ }
{‘YPos(mm)’}
{‘Sep1’ }
{‘Sep2’ }
{‘<Sep>’ }
{‘dpixel’ }
ans =
TableProperties with properties:
Description: ‘Surface Profile’
UserData: []
DimensionNames: {‘Row’ ‘Variables’}
VariableNames: {‘Idx’ ‘YPos(mm)’ ‘Sep1’ ‘Sep2’ ‘<Sep>’ ‘dpixel’}
VariableDescriptions: {}
VariableUnits: {}
VariableContinuity: []
RowNames: {}
Custom Properties (access using t.Properties.CustomProperties.<name>):
ScanStart: "29-Jan-2025 09:41:35"
ScanTime: ‘174.2796’
But then the file looks like this:
So no headings.
And When i also try to load via readtable – all of the description and custom propeerrties are not present
ans =
TableProperties with properties:
Description: ”
UserData: []
DimensionNames: {‘Row’ ‘Variables’}
VariableNames: {‘Var1’ ‘Var2’ ‘Var3’ ‘Var4’ ‘Var5’ ‘Var6’}
VariableDescriptions: {}
VariableUnits: {}
VariableContinuity: []
RowNames: {}
CustomProperties: No custom properties are set.
Use addprop and rmprop to modify CustomProperties. Hello, I have an array in a uitable that I want to save to a csv file as well as the column headings. It seems out of the write options available (writecell,writematrix, writetable) – it is only writetable that allows this
Writetable appears to work, but when I open the CSV file it hasn’t and I can’t understand why
This is my code:
T=app.UITable;
data=T.Data;
C=array2table(data); % Create table format
T.ColumnName
C.Properties.VariableNames=T.ColumnName;
C.Properties.Description=’Scan Profile’;
C = addprop(C,{‘ScanStart’,’ScanTime’},{‘table’,’table’});
C.Properties.CustomProperties.ScanStart = app.scannow;
C.Properties.CustomProperties.ScanTime = app.scantime;
C.Properties
% C.Properties.VariableNames
writetable(C,savepath);
ReportMessage(app,’ Data Saved Using Writetable’);
And in the command window I get this, indicating all is O.K
ans =
6×1 cell array
{‘Idx’ }
{‘YPos(mm)’}
{‘Sep1’ }
{‘Sep2’ }
{‘<Sep>’ }
{‘dpixel’ }
ans =
TableProperties with properties:
Description: ‘Surface Profile’
UserData: []
DimensionNames: {‘Row’ ‘Variables’}
VariableNames: {‘Idx’ ‘YPos(mm)’ ‘Sep1’ ‘Sep2’ ‘<Sep>’ ‘dpixel’}
VariableDescriptions: {}
VariableUnits: {}
VariableContinuity: []
RowNames: {}
Custom Properties (access using t.Properties.CustomProperties.<name>):
ScanStart: "29-Jan-2025 09:41:35"
ScanTime: ‘174.2796’
But then the file looks like this:
So no headings.
And When i also try to load via readtable – all of the description and custom propeerrties are not present
ans =
TableProperties with properties:
Description: ”
UserData: []
DimensionNames: {‘Row’ ‘Variables’}
VariableNames: {‘Var1’ ‘Var2’ ‘Var3’ ‘Var4’ ‘Var5’ ‘Var6’}
VariableDescriptions: {}
VariableUnits: {}
VariableContinuity: []
RowNames: {}
CustomProperties: No custom properties are set.
Use addprop and rmprop to modify CustomProperties. writetable, uitable MATLAB Answers — New Questions
How to fix an error that the ‘MATLAB Vault is unavailable’ when using the commands listSecrets or setSecret?
I use the MATLAB vault functions to store secrets like logins, passwords, etc in MATLAB 2024a.
It had been working perfectly fine for several months, but suddenly whenever I call any functions like listSecrets, getSecret, setSecret I get this error:
Unable to call ‘listSecrets’. The MATLAB Vault is unavailable.
I have tried the following with no luck:
restarting MATLAB
restarting my PC
re-installing MATLAB
I got this error once before, but after restarting MATLAB it went away. But now, no amount of restarting MATLAB has been able to fix it.
Is there a way to fix this error?I use the MATLAB vault functions to store secrets like logins, passwords, etc in MATLAB 2024a.
It had been working perfectly fine for several months, but suddenly whenever I call any functions like listSecrets, getSecret, setSecret I get this error:
Unable to call ‘listSecrets’. The MATLAB Vault is unavailable.
I have tried the following with no luck:
restarting MATLAB
restarting my PC
re-installing MATLAB
I got this error once before, but after restarting MATLAB it went away. But now, no amount of restarting MATLAB has been able to fix it.
Is there a way to fix this error? I use the MATLAB vault functions to store secrets like logins, passwords, etc in MATLAB 2024a.
It had been working perfectly fine for several months, but suddenly whenever I call any functions like listSecrets, getSecret, setSecret I get this error:
Unable to call ‘listSecrets’. The MATLAB Vault is unavailable.
I have tried the following with no luck:
restarting MATLAB
restarting my PC
re-installing MATLAB
I got this error once before, but after restarting MATLAB it went away. But now, no amount of restarting MATLAB has been able to fix it.
Is there a way to fix this error? vault MATLAB Answers — New Questions
Why my 2 legs inverter doesn’t output the expected voltage?
Why my 2 legs inverter doesn’t output the expected voltage?
I expected the bridge voltage varying binary between 0 and Vbat when I want my motor turns in one sense.
Or -Vbat to 0 whent I want motor turns in the other sense.
instead of the bridge voltage varies from Vbat/2 to Vbat or fron -Vbat to -Vbat/2.
Someone can explain to me how can I fix this issue?Why my 2 legs inverter doesn’t output the expected voltage?
I expected the bridge voltage varying binary between 0 and Vbat when I want my motor turns in one sense.
Or -Vbat to 0 whent I want motor turns in the other sense.
instead of the bridge voltage varies from Vbat/2 to Vbat or fron -Vbat to -Vbat/2.
Someone can explain to me how can I fix this issue? Why my 2 legs inverter doesn’t output the expected voltage?
I expected the bridge voltage varying binary between 0 and Vbat when I want my motor turns in one sense.
Or -Vbat to 0 whent I want motor turns in the other sense.
instead of the bridge voltage varies from Vbat/2 to Vbat or fron -Vbat to -Vbat/2.
Someone can explain to me how can I fix this issue? motor control MATLAB Answers — New Questions
Multiple regression with nonlinear variables
Hello,
I am working with the attached dataset, where the first column represents temperature and the next six columns (2–7) correspond to temperature-dependent properties.
I would like to explore whether it is possible to model temperature as a function of these six properties simultaneously, similar to a multiple regression approach. I have previously done this with linear responses, but in this case, the relationships are nonlinear (sigmoidal, Z-shaped).
I considered using a generalized additive model (GAM), but I have no prior experience with this method and may be overlooking a simpler or more suitable approach.
Could anyone provide insights or suggestions on how to best tackle this?
Thanks in advance! :)Hello,
I am working with the attached dataset, where the first column represents temperature and the next six columns (2–7) correspond to temperature-dependent properties.
I would like to explore whether it is possible to model temperature as a function of these six properties simultaneously, similar to a multiple regression approach. I have previously done this with linear responses, but in this case, the relationships are nonlinear (sigmoidal, Z-shaped).
I considered using a generalized additive model (GAM), but I have no prior experience with this method and may be overlooking a simpler or more suitable approach.
Could anyone provide insights or suggestions on how to best tackle this?
Thanks in advance! 🙂 Hello,
I am working with the attached dataset, where the first column represents temperature and the next six columns (2–7) correspond to temperature-dependent properties.
I would like to explore whether it is possible to model temperature as a function of these six properties simultaneously, similar to a multiple regression approach. I have previously done this with linear responses, but in this case, the relationships are nonlinear (sigmoidal, Z-shaped).
I considered using a generalized additive model (GAM), but I have no prior experience with this method and may be overlooking a simpler or more suitable approach.
Could anyone provide insights or suggestions on how to best tackle this?
Thanks in advance! 🙂 multiple regression, nonlinear, additive models, multiple variables MATLAB Answers — New Questions
fmincon with simulink model
Hello, I’m struggling with fmincon, as I’m still a beginner. I have a Simulink model that simulates the behavior of an electric vehicle and a track specification (maximum speed in different sections, total length).
The model takes as input the throttle and brake pedal pressures (steering is not relevant in this case) and outputs various vehicle dynamics parameters such as speed, jerk, acceleration, and SoC.
My goal is to determine the optimal pedal usage to complete the track while maximizing the remaining SoC, using the results obtained from the model.
I wrote a MATLAB script for this, but the throttle and brake pedal vectors never change—they always remain the same as the initial values u0 that I provide.
Does anyone know what might be causing this issue?
My cost function is:
function [cost, c, ceq] = myCostAndConstraints(u, timeVec, steeringTS, w1, w2, w3, w4, w5, total_distance)
N = length(u)/2;
throttleProfile = u(1:N);
brakeProfile = u(N+1:end);
myThrottleTs = timeseries(throttleProfile, timeVec);
myBrakeTs = timeseries(brakeProfile, timeVec);
in = Simulink.SimulationInput(‘optimization_offline_model’);
in = in.setVariable(‘myThrottleTs’, myThrottleTs);
in = in.setVariable(‘myBrakeTs’, myBrakeTs);
in = in.setVariable(‘steeringWheelAngle_ts’, steeringTS);
try
simOut = sim(in);
catch ME
warning("Simulation error: %s" + ME.message);
cost = 1e6;
c = 1e5;
ceq = [];
return;
end
try
timeSim = simOut.tout;
speedData = simOut.v_z.Data;
SoCData = simOut.SoC.Data;
jerkData = simOut.j_z.Data;
distanceData = simOut.distance.Data;
catch ME
warning("Error extracting signals: " + ME.message);
cost = 1e6;
c = 1e5;
ceq = [];
return;
end
SoC_final = SoCData(end);
time_elapsed = timeSim(end);
distance_final = distanceData(end);
penalty = 0;
if any(SoCData < 0.2)
penalty = penalty + w1 * (0.2 – min(SoCData(SoCData<0.2)));
end
vLimHard = 41.5;
violV = speedData – vLimHard;
violV(violV<0) = 0;
if any(violV > 0)
penalty = penalty + w5 * sum(violV);
end
avgJerk = mean(jerkData);
maxJerk = max(abs(jerkData));
penalty = penalty + w3*(max(0, 0.2 – avgJerk))^2 + w3*(max(0, avgJerk – 0.7))^2;
if avgJerk > 0.6
penalty = penalty + w3*(avgJerk – 0.6);
end
if maxJerk > 0.9
penalty = penalty + w3*(maxJerk – 0.9);
end
cost = – w1*SoC_final + w2*(time_elapsed) + w4 * abs(total_distance – distance_final) + penalty;
disp("Cost function =" + cost);
vLimVec = getVelocityLimit(distanceData, vLimHard);
c = speedData – vLimVec;
ceq = throttleProfile .* brakeProfile;
endHello, I’m struggling with fmincon, as I’m still a beginner. I have a Simulink model that simulates the behavior of an electric vehicle and a track specification (maximum speed in different sections, total length).
The model takes as input the throttle and brake pedal pressures (steering is not relevant in this case) and outputs various vehicle dynamics parameters such as speed, jerk, acceleration, and SoC.
My goal is to determine the optimal pedal usage to complete the track while maximizing the remaining SoC, using the results obtained from the model.
I wrote a MATLAB script for this, but the throttle and brake pedal vectors never change—they always remain the same as the initial values u0 that I provide.
Does anyone know what might be causing this issue?
My cost function is:
function [cost, c, ceq] = myCostAndConstraints(u, timeVec, steeringTS, w1, w2, w3, w4, w5, total_distance)
N = length(u)/2;
throttleProfile = u(1:N);
brakeProfile = u(N+1:end);
myThrottleTs = timeseries(throttleProfile, timeVec);
myBrakeTs = timeseries(brakeProfile, timeVec);
in = Simulink.SimulationInput(‘optimization_offline_model’);
in = in.setVariable(‘myThrottleTs’, myThrottleTs);
in = in.setVariable(‘myBrakeTs’, myBrakeTs);
in = in.setVariable(‘steeringWheelAngle_ts’, steeringTS);
try
simOut = sim(in);
catch ME
warning("Simulation error: %s" + ME.message);
cost = 1e6;
c = 1e5;
ceq = [];
return;
end
try
timeSim = simOut.tout;
speedData = simOut.v_z.Data;
SoCData = simOut.SoC.Data;
jerkData = simOut.j_z.Data;
distanceData = simOut.distance.Data;
catch ME
warning("Error extracting signals: " + ME.message);
cost = 1e6;
c = 1e5;
ceq = [];
return;
end
SoC_final = SoCData(end);
time_elapsed = timeSim(end);
distance_final = distanceData(end);
penalty = 0;
if any(SoCData < 0.2)
penalty = penalty + w1 * (0.2 – min(SoCData(SoCData<0.2)));
end
vLimHard = 41.5;
violV = speedData – vLimHard;
violV(violV<0) = 0;
if any(violV > 0)
penalty = penalty + w5 * sum(violV);
end
avgJerk = mean(jerkData);
maxJerk = max(abs(jerkData));
penalty = penalty + w3*(max(0, 0.2 – avgJerk))^2 + w3*(max(0, avgJerk – 0.7))^2;
if avgJerk > 0.6
penalty = penalty + w3*(avgJerk – 0.6);
end
if maxJerk > 0.9
penalty = penalty + w3*(maxJerk – 0.9);
end
cost = – w1*SoC_final + w2*(time_elapsed) + w4 * abs(total_distance – distance_final) + penalty;
disp("Cost function =" + cost);
vLimVec = getVelocityLimit(distanceData, vLimHard);
c = speedData – vLimVec;
ceq = throttleProfile .* brakeProfile;
end Hello, I’m struggling with fmincon, as I’m still a beginner. I have a Simulink model that simulates the behavior of an electric vehicle and a track specification (maximum speed in different sections, total length).
The model takes as input the throttle and brake pedal pressures (steering is not relevant in this case) and outputs various vehicle dynamics parameters such as speed, jerk, acceleration, and SoC.
My goal is to determine the optimal pedal usage to complete the track while maximizing the remaining SoC, using the results obtained from the model.
I wrote a MATLAB script for this, but the throttle and brake pedal vectors never change—they always remain the same as the initial values u0 that I provide.
Does anyone know what might be causing this issue?
My cost function is:
function [cost, c, ceq] = myCostAndConstraints(u, timeVec, steeringTS, w1, w2, w3, w4, w5, total_distance)
N = length(u)/2;
throttleProfile = u(1:N);
brakeProfile = u(N+1:end);
myThrottleTs = timeseries(throttleProfile, timeVec);
myBrakeTs = timeseries(brakeProfile, timeVec);
in = Simulink.SimulationInput(‘optimization_offline_model’);
in = in.setVariable(‘myThrottleTs’, myThrottleTs);
in = in.setVariable(‘myBrakeTs’, myBrakeTs);
in = in.setVariable(‘steeringWheelAngle_ts’, steeringTS);
try
simOut = sim(in);
catch ME
warning("Simulation error: %s" + ME.message);
cost = 1e6;
c = 1e5;
ceq = [];
return;
end
try
timeSim = simOut.tout;
speedData = simOut.v_z.Data;
SoCData = simOut.SoC.Data;
jerkData = simOut.j_z.Data;
distanceData = simOut.distance.Data;
catch ME
warning("Error extracting signals: " + ME.message);
cost = 1e6;
c = 1e5;
ceq = [];
return;
end
SoC_final = SoCData(end);
time_elapsed = timeSim(end);
distance_final = distanceData(end);
penalty = 0;
if any(SoCData < 0.2)
penalty = penalty + w1 * (0.2 – min(SoCData(SoCData<0.2)));
end
vLimHard = 41.5;
violV = speedData – vLimHard;
violV(violV<0) = 0;
if any(violV > 0)
penalty = penalty + w5 * sum(violV);
end
avgJerk = mean(jerkData);
maxJerk = max(abs(jerkData));
penalty = penalty + w3*(max(0, 0.2 – avgJerk))^2 + w3*(max(0, avgJerk – 0.7))^2;
if avgJerk > 0.6
penalty = penalty + w3*(avgJerk – 0.6);
end
if maxJerk > 0.9
penalty = penalty + w3*(maxJerk – 0.9);
end
cost = – w1*SoC_final + w2*(time_elapsed) + w4 * abs(total_distance – distance_final) + penalty;
disp("Cost function =" + cost);
vLimVec = getVelocityLimit(distanceData, vLimHard);
c = speedData – vLimVec;
ceq = throttleProfile .* brakeProfile;
end fmincon, simulink MATLAB Answers — New Questions
How to use index an image using color inequality?
I have an image that I would like to turn black or white depending on a user defined color RGB value associated with the scale in the image. How would I do this?I have an image that I would like to turn black or white depending on a user defined color RGB value associated with the scale in the image. How would I do this? I have an image that I would like to turn black or white depending on a user defined color RGB value associated with the scale in the image. How would I do this? indexing, image processing MATLAB Answers — New Questions
Definition of “Frame” for Recurrent models
Hi all,
I am profiling the performance of the MATLAB Deep Learning HDL Toolbox for LSTM-based models.
When estimating the processor’s performance with the estimatePerformance function, I couldn’t find a clear definition of the term "Frame" in the context of recurrent models.
Does it refer to a single element within the sequence to be processed (i.e. a timestep), or does it represent the entire sequence?
Since changing the number of timesteps in the model doesn’t affect the processing time estimate for 1 frame, I am assuming it refers to a single element of the sequence. However, I would appreciate confirmation or clarification on this.
Thanks in advance for your help!Hi all,
I am profiling the performance of the MATLAB Deep Learning HDL Toolbox for LSTM-based models.
When estimating the processor’s performance with the estimatePerformance function, I couldn’t find a clear definition of the term "Frame" in the context of recurrent models.
Does it refer to a single element within the sequence to be processed (i.e. a timestep), or does it represent the entire sequence?
Since changing the number of timesteps in the model doesn’t affect the processing time estimate for 1 frame, I am assuming it refers to a single element of the sequence. However, I would appreciate confirmation or clarification on this.
Thanks in advance for your help! Hi all,
I am profiling the performance of the MATLAB Deep Learning HDL Toolbox for LSTM-based models.
When estimating the processor’s performance with the estimatePerformance function, I couldn’t find a clear definition of the term "Frame" in the context of recurrent models.
Does it refer to a single element within the sequence to be processed (i.e. a timestep), or does it represent the entire sequence?
Since changing the number of timesteps in the model doesn’t affect the processing time estimate for 1 frame, I am assuming it refers to a single element of the sequence. However, I would appreciate confirmation or clarification on this.
Thanks in advance for your help! lstm, deep learning hdl toolbox MATLAB Answers — New Questions
How does multithresh and imquantize works
Can anyone explain about multithresh and imquantize? I’ve read the documentation regarding it but I don’t really understand how does it works and how do they relate to each other.
If i have a thresh = multithresh(A,4)
Does it means that it returns 4 threshold values from the image? How does the system decides which values to return? And we have imquantize(A,thresh). What would happen?Can anyone explain about multithresh and imquantize? I’ve read the documentation regarding it but I don’t really understand how does it works and how do they relate to each other.
If i have a thresh = multithresh(A,4)
Does it means that it returns 4 threshold values from the image? How does the system decides which values to return? And we have imquantize(A,thresh). What would happen? Can anyone explain about multithresh and imquantize? I’ve read the documentation regarding it but I don’t really understand how does it works and how do they relate to each other.
If i have a thresh = multithresh(A,4)
Does it means that it returns 4 threshold values from the image? How does the system decides which values to return? And we have imquantize(A,thresh). What would happen? image processing MATLAB Answers — New Questions
simpowersysteme discret simulation stability issue
I want to analyse the transient stability of a simple system over a long period of time. I do this because my ultimate goal is to run the simulation with real-time simulator for education purpose.
My model is really simple, one PV bus synchronous generator connected to a infinite swing bus via a bunch of inductance and resistance in serie and parallel. I simulate a fault at 0.5 sec and since i am simulating dampingless generator i expect my system to oscillate for the infinity
But.. When i run my model in phasor mode it run well and it do not diverge. But when i run it in discret mode with 20 us (as it will be on my real time simulator) the mecanical angle after the fault always increase until it reach instability.
btw i add up some extra load to help numerical stability as suggested in the help panel of the synchronous generator.I want to analyse the transient stability of a simple system over a long period of time. I do this because my ultimate goal is to run the simulation with real-time simulator for education purpose.
My model is really simple, one PV bus synchronous generator connected to a infinite swing bus via a bunch of inductance and resistance in serie and parallel. I simulate a fault at 0.5 sec and since i am simulating dampingless generator i expect my system to oscillate for the infinity
But.. When i run my model in phasor mode it run well and it do not diverge. But when i run it in discret mode with 20 us (as it will be on my real time simulator) the mecanical angle after the fault always increase until it reach instability.
btw i add up some extra load to help numerical stability as suggested in the help panel of the synchronous generator. I want to analyse the transient stability of a simple system over a long period of time. I do this because my ultimate goal is to run the simulation with real-time simulator for education purpose.
My model is really simple, one PV bus synchronous generator connected to a infinite swing bus via a bunch of inductance and resistance in serie and parallel. I simulate a fault at 0.5 sec and since i am simulating dampingless generator i expect my system to oscillate for the infinity
But.. When i run my model in phasor mode it run well and it do not diverge. But when i run it in discret mode with 20 us (as it will be on my real time simulator) the mecanical angle after the fault always increase until it reach instability.
btw i add up some extra load to help numerical stability as suggested in the help panel of the synchronous generator. simulink, simpowersystems, simulation MATLAB Answers — New Questions
How can I break a WHILE or a FOR loop in Simulink?
I want to break a for loop or a while loop in Simulink. For instance, we have break statement in C. How do I do the same in Simulink?I want to break a for loop or a while loop in Simulink. For instance, we have break statement in C. How do I do the same in Simulink? I want to break a for loop or a while loop in Simulink. For instance, we have break statement in C. How do I do the same in Simulink? break, for loop, while loop MATLAB Answers — New Questions
How do I obtain area under selected region on figure?
I am trying to select peak start and end points and calculate area under the curve for several regions of interest. Is there an easy way to do it quickly on the figure itself? A sample image is attached with selected (X1,Y1) and (X2,Y2) points as an example.I am trying to select peak start and end points and calculate area under the curve for several regions of interest. Is there an easy way to do it quickly on the figure itself? A sample image is attached with selected (X1,Y1) and (X2,Y2) points as an example. I am trying to select peak start and end points and calculate area under the curve for several regions of interest. Is there an easy way to do it quickly on the figure itself? A sample image is attached with selected (X1,Y1) and (X2,Y2) points as an example. figure, image processing, matlab MATLAB Answers — New Questions
three phase transformer simulation
Hi
I am doing simulation for a three-phase transformer (50/11) KV with is feeding by avoltage source, while the secondery is coneectred to ta fixed load.
when I run the simulation. the voltage measurement in the primary winding for the transformer is very small and there is no current, the same thing is happing in the secondary.
I am going to upload the simulation file. anyone can help ?Hi
I am doing simulation for a three-phase transformer (50/11) KV with is feeding by avoltage source, while the secondery is coneectred to ta fixed load.
when I run the simulation. the voltage measurement in the primary winding for the transformer is very small and there is no current, the same thing is happing in the secondary.
I am going to upload the simulation file. anyone can help ? Hi
I am doing simulation for a three-phase transformer (50/11) KV with is feeding by avoltage source, while the secondery is coneectred to ta fixed load.
when I run the simulation. the voltage measurement in the primary winding for the transformer is very small and there is no current, the same thing is happing in the secondary.
I am going to upload the simulation file. anyone can help ? simulation, transformer MATLAB Answers — New Questions
Error message: Matrix Dimensions must agree
Not sure what I am doing wrong:
syms x
n = 0:1:100;
t = 0:0.1:50;
lamda = (n .* pi);
u = (100 .* cosd(lamda .* x) + (sind(lamda .* x)) .* (exp((-lamda .^ 2) .* t) ;
fplot(t,u)
grid on
Thank youNot sure what I am doing wrong:
syms x
n = 0:1:100;
t = 0:0.1:50;
lamda = (n .* pi);
u = (100 .* cosd(lamda .* x) + (sind(lamda .* x)) .* (exp((-lamda .^ 2) .* t) ;
fplot(t,u)
grid on
Thank you Not sure what I am doing wrong:
syms x
n = 0:1:100;
t = 0:0.1:50;
lamda = (n .* pi);
u = (100 .* cosd(lamda .* x) + (sind(lamda .* x)) .* (exp((-lamda .^ 2) .* t) ;
fplot(t,u)
grid on
Thank you matrix dimensions must agree MATLAB Answers — New Questions
Least Frequent Words in document
If I use topkwords to find the most-frequent words, what code can I use to show the 10-least frequent words?If I use topkwords to find the most-frequent words, what code can I use to show the 10-least frequent words? If I use topkwords to find the most-frequent words, what code can I use to show the 10-least frequent words? textanalyticstoolbox MATLAB Answers — New Questions
Eliminate for-loop in recursive computation?
I’m trying to speed up a recursive calculation that is currently using a for-loop. A minimum working example is below. There are two computations in the recursion: "pn0" and "fact". I have figured out how to do fact out side the loop, but pn0 is giving me trouble. Any insight into how to remove the loop and/or speed this up would be greatly appreaciated! I have tried building up a separate function and using arrayfun, but that is calling a loop under the hood, so I don’t think it would be faster.
% define some constants
m = 0:10;
y = cos(pi/4);
% compute fact without a loop
fact = cumsum([1 ones(1,size(m,2)).*2]);
fact = fact(1:end-1);
% Generate the correct pn0 array
pn0 = 1; % initial value
factdum = 1; % initial value
pn_out = [];
fact_out = [];
for mm = 0:10
pn0 = -pn0*factdum*y; % do the computation <– this is the computation I’m trying to pull out of the loop
pn_out = [pn_out,pn0]; % store the pn0 array output
fact_out = [fact_out,factdum]; % store the fact array output
factdum = factdum + 2; % compute fact inside the loop to make sure it was done correctly outside the loop.
endI’m trying to speed up a recursive calculation that is currently using a for-loop. A minimum working example is below. There are two computations in the recursion: "pn0" and "fact". I have figured out how to do fact out side the loop, but pn0 is giving me trouble. Any insight into how to remove the loop and/or speed this up would be greatly appreaciated! I have tried building up a separate function and using arrayfun, but that is calling a loop under the hood, so I don’t think it would be faster.
% define some constants
m = 0:10;
y = cos(pi/4);
% compute fact without a loop
fact = cumsum([1 ones(1,size(m,2)).*2]);
fact = fact(1:end-1);
% Generate the correct pn0 array
pn0 = 1; % initial value
factdum = 1; % initial value
pn_out = [];
fact_out = [];
for mm = 0:10
pn0 = -pn0*factdum*y; % do the computation <– this is the computation I’m trying to pull out of the loop
pn_out = [pn_out,pn0]; % store the pn0 array output
fact_out = [fact_out,factdum]; % store the fact array output
factdum = factdum + 2; % compute fact inside the loop to make sure it was done correctly outside the loop.
end I’m trying to speed up a recursive calculation that is currently using a for-loop. A minimum working example is below. There are two computations in the recursion: "pn0" and "fact". I have figured out how to do fact out side the loop, but pn0 is giving me trouble. Any insight into how to remove the loop and/or speed this up would be greatly appreaciated! I have tried building up a separate function and using arrayfun, but that is calling a loop under the hood, so I don’t think it would be faster.
% define some constants
m = 0:10;
y = cos(pi/4);
% compute fact without a loop
fact = cumsum([1 ones(1,size(m,2)).*2]);
fact = fact(1:end-1);
% Generate the correct pn0 array
pn0 = 1; % initial value
factdum = 1; % initial value
pn_out = [];
fact_out = [];
for mm = 0:10
pn0 = -pn0*factdum*y; % do the computation <– this is the computation I’m trying to pull out of the loop
pn_out = [pn_out,pn0]; % store the pn0 array output
fact_out = [fact_out,factdum]; % store the fact array output
factdum = factdum + 2; % compute fact inside the loop to make sure it was done correctly outside the loop.
end recursion, eliminate for loop MATLAB Answers — New Questions
Error plot is starting at the wrong value in my “while loop”
clear all
w=(12.35)^0.5;
%theta_exact=10*exp(-2*t)*cos(t*w)+20*exp(-2*t)*sin(w*t);
theta1(1)=10; %deg
psy1(1)=0; %deg/s
g=9.81; %m/s^2
c=4; %1/s
l=0.6; %m
dt1=0.1;
t1(1)=0;
i=1;
while t1<6
theta1(i+1)=theta1(i)+psy1(i)*dt1
psy1(i+1)=(-g/l)*dt1*theta1(i)+(1-c*dt1)*psy1(i);
theta_exact=10.*exp(-2.*t1).*cos(w.*t1)+(20/w).*exp(-2.*t1).*sin(w.*t1)
epsilon1=(theta1(i)-theta_exact)
t1(i+1)=t1(i)+dt1;
i=i+1;
end
figure(1); clf;
hold on
plot(t1,theta1,’red’)
plot(t1(1:end-1),theta_exact,’blue’)
figure(2); clf;
plot(t1(1:end-1),(epsilon1))
If you read the code you notice that the second plot is a time vs "epsilon1". My issue is that the first value for "epsilon1" is -10 but epsilon1=(theta1(i)-theta_exact), where theta1(i) and theta_exact are the same value for their first values. The first value should read 0 for epsilon1, can anyone help me figure out why this is not the case?clear all
w=(12.35)^0.5;
%theta_exact=10*exp(-2*t)*cos(t*w)+20*exp(-2*t)*sin(w*t);
theta1(1)=10; %deg
psy1(1)=0; %deg/s
g=9.81; %m/s^2
c=4; %1/s
l=0.6; %m
dt1=0.1;
t1(1)=0;
i=1;
while t1<6
theta1(i+1)=theta1(i)+psy1(i)*dt1
psy1(i+1)=(-g/l)*dt1*theta1(i)+(1-c*dt1)*psy1(i);
theta_exact=10.*exp(-2.*t1).*cos(w.*t1)+(20/w).*exp(-2.*t1).*sin(w.*t1)
epsilon1=(theta1(i)-theta_exact)
t1(i+1)=t1(i)+dt1;
i=i+1;
end
figure(1); clf;
hold on
plot(t1,theta1,’red’)
plot(t1(1:end-1),theta_exact,’blue’)
figure(2); clf;
plot(t1(1:end-1),(epsilon1))
If you read the code you notice that the second plot is a time vs "epsilon1". My issue is that the first value for "epsilon1" is -10 but epsilon1=(theta1(i)-theta_exact), where theta1(i) and theta_exact are the same value for their first values. The first value should read 0 for epsilon1, can anyone help me figure out why this is not the case? clear all
w=(12.35)^0.5;
%theta_exact=10*exp(-2*t)*cos(t*w)+20*exp(-2*t)*sin(w*t);
theta1(1)=10; %deg
psy1(1)=0; %deg/s
g=9.81; %m/s^2
c=4; %1/s
l=0.6; %m
dt1=0.1;
t1(1)=0;
i=1;
while t1<6
theta1(i+1)=theta1(i)+psy1(i)*dt1
psy1(i+1)=(-g/l)*dt1*theta1(i)+(1-c*dt1)*psy1(i);
theta_exact=10.*exp(-2.*t1).*cos(w.*t1)+(20/w).*exp(-2.*t1).*sin(w.*t1)
epsilon1=(theta1(i)-theta_exact)
t1(i+1)=t1(i)+dt1;
i=i+1;
end
figure(1); clf;
hold on
plot(t1,theta1,’red’)
plot(t1(1:end-1),theta_exact,’blue’)
figure(2); clf;
plot(t1(1:end-1),(epsilon1))
If you read the code you notice that the second plot is a time vs "epsilon1". My issue is that the first value for "epsilon1" is -10 but epsilon1=(theta1(i)-theta_exact), where theta1(i) and theta_exact are the same value for their first values. The first value should read 0 for epsilon1, can anyone help me figure out why this is not the case? while loop, forward differencing MATLAB Answers — New Questions
OPC DA Write issues
Hi I used to program on Simulink using the OPC DA Config, OPC Write/Read blocks and till version 2017 it worked just fine. Now I implemented it on 2024b version and by the time I want to test it there’s this error that says:
Error:The corresponding ‘opcslwrite.tlc’ file for the MATLAB S-function ‘opcslwrite’ in block ‘hardprog/OPC Write’ must be located in the current working directory, the MATLAB S-function directory ‘C:Program FilesMATLABR2024btoolboxicommopcopcblksopcblks’, or the directory ‘C:Program FilesMATLABR2024btoolboxicommopcopcblksopcblkstlc_c’
I can configure the OPC DA Config Real-Time block, but when I try to add a tag there’s a sound of error and the Browse Name Space shows up but I can’t click in OK nor Cancel it remains there and then I can’t do a thing.
Thank you!Hi I used to program on Simulink using the OPC DA Config, OPC Write/Read blocks and till version 2017 it worked just fine. Now I implemented it on 2024b version and by the time I want to test it there’s this error that says:
Error:The corresponding ‘opcslwrite.tlc’ file for the MATLAB S-function ‘opcslwrite’ in block ‘hardprog/OPC Write’ must be located in the current working directory, the MATLAB S-function directory ‘C:Program FilesMATLABR2024btoolboxicommopcopcblksopcblks’, or the directory ‘C:Program FilesMATLABR2024btoolboxicommopcopcblksopcblkstlc_c’
I can configure the OPC DA Config Real-Time block, but when I try to add a tag there’s a sound of error and the Browse Name Space shows up but I can’t click in OK nor Cancel it remains there and then I can’t do a thing.
Thank you! Hi I used to program on Simulink using the OPC DA Config, OPC Write/Read blocks and till version 2017 it worked just fine. Now I implemented it on 2024b version and by the time I want to test it there’s this error that says:
Error:The corresponding ‘opcslwrite.tlc’ file for the MATLAB S-function ‘opcslwrite’ in block ‘hardprog/OPC Write’ must be located in the current working directory, the MATLAB S-function directory ‘C:Program FilesMATLABR2024btoolboxicommopcopcblksopcblks’, or the directory ‘C:Program FilesMATLABR2024btoolboxicommopcopcblksopcblkstlc_c’
I can configure the OPC DA Config Real-Time block, but when I try to add a tag there’s a sound of error and the Browse Name Space shows up but I can’t click in OK nor Cancel it remains there and then I can’t do a thing.
Thank you! opc, simulink, tlc MATLAB Answers — New Questions
why won’t this work?
I want this code to read a text file, convert it to ASCII Characters, make a pie chart over the ten most occurring numbers, be able to change for instance an "a" to "c" (two steps) and the program to make two steps everywhere in the text and then print the new text.
Will be very grateful for your help!
fid=fopen(‘krypterad1.txt’,’rt’);%Open text file
text = fscanf(fid,’%c’,Inf);%Read text file
text = upper(text);%Convert to upper cases
nummer = double(text);%Convert text to Ascii
n = histc(nummer, 65:90);
for nummer =65:90;
for antal=1:n
end
end
[B,IX] = sort(n, ‘descend’);%Sort array B in descending order
fprintf(‘%dn’,B);%Print array B
pie(B(1,10)’)%Make pie chart of the ten most occuring numbers in the array (doesn’t work)
title(‘De 10 mest förekommande bokstäverna i texten’)%Chart title
f = input(‘byt från ‘,’s’)
t = input(’till ‘,’s’)
diff = double(t) – double(f)
for rulla = nummer-(diff)
if rulla<=64, rulla=rulla+26; end
if rulla>90, rulla=rulla-26; end
okodadtext = char(rulla);
fprintf(‘%s’,okodadtext)
endI want this code to read a text file, convert it to ASCII Characters, make a pie chart over the ten most occurring numbers, be able to change for instance an "a" to "c" (two steps) and the program to make two steps everywhere in the text and then print the new text.
Will be very grateful for your help!
fid=fopen(‘krypterad1.txt’,’rt’);%Open text file
text = fscanf(fid,’%c’,Inf);%Read text file
text = upper(text);%Convert to upper cases
nummer = double(text);%Convert text to Ascii
n = histc(nummer, 65:90);
for nummer =65:90;
for antal=1:n
end
end
[B,IX] = sort(n, ‘descend’);%Sort array B in descending order
fprintf(‘%dn’,B);%Print array B
pie(B(1,10)’)%Make pie chart of the ten most occuring numbers in the array (doesn’t work)
title(‘De 10 mest förekommande bokstäverna i texten’)%Chart title
f = input(‘byt från ‘,’s’)
t = input(’till ‘,’s’)
diff = double(t) – double(f)
for rulla = nummer-(diff)
if rulla<=64, rulla=rulla+26; end
if rulla>90, rulla=rulla-26; end
okodadtext = char(rulla);
fprintf(‘%s’,okodadtext)
end I want this code to read a text file, convert it to ASCII Characters, make a pie chart over the ten most occurring numbers, be able to change for instance an "a" to "c" (two steps) and the program to make two steps everywhere in the text and then print the new text.
Will be very grateful for your help!
fid=fopen(‘krypterad1.txt’,’rt’);%Open text file
text = fscanf(fid,’%c’,Inf);%Read text file
text = upper(text);%Convert to upper cases
nummer = double(text);%Convert text to Ascii
n = histc(nummer, 65:90);
for nummer =65:90;
for antal=1:n
end
end
[B,IX] = sort(n, ‘descend’);%Sort array B in descending order
fprintf(‘%dn’,B);%Print array B
pie(B(1,10)’)%Make pie chart of the ten most occuring numbers in the array (doesn’t work)
title(‘De 10 mest förekommande bokstäverna i texten’)%Chart title
f = input(‘byt från ‘,’s’)
t = input(’till ‘,’s’)
diff = double(t) – double(f)
for rulla = nummer-(diff)
if rulla<=64, rulla=rulla+26; end
if rulla>90, rulla=rulla-26; end
okodadtext = char(rulla);
fprintf(‘%s’,okodadtext)
end for loop, pie, if statement MATLAB Answers — New Questions
Finite Element Analysis for Fixed Ended Beam with a Point Load example: I am getting this error: Error using * Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the se
Fixed Ended Beam with Point Load Example
%Data
E = 2.1E5; % N/mm^2
L = 6000; % length in mm
I = 78E6; % mm^4
Elemental Stiffness Matrix
Const = (E*I)/(L^3);
%Since we only have one element this is the overall
%stiffness matrix
KE1 = [12 6*L -12 6*L;
6*L 4*L^2 -6*L 2*L^2;
-12 -6*L 12 -6*L;
6*L 2*L^2 -6*L 4*L^2];
KE1 = Const*KE1;
Solution
K = KE1;
KT = K;
KT(:,1) = 0;
KT(1,:) = 0;
KT(1,1) = 1;
KT(:,2) = 0;
KT(2,:) = 0;
KT(2,2) = 1;
KT(:,4) = 0;
KT(4,:) = 0;
KT(4,4) = 1;
KT(:,5) = 0;
KT(5,:) = 0;
KT(5,5) = 1;
KT(:,6) = 0;
KT(6,:) = 0;
KT(6,6) = 1;
KT
FT = [0;0; -50;0; 0;0];
d = inv(KT)*FT
F = K*dFixed Ended Beam with Point Load Example
%Data
E = 2.1E5; % N/mm^2
L = 6000; % length in mm
I = 78E6; % mm^4
Elemental Stiffness Matrix
Const = (E*I)/(L^3);
%Since we only have one element this is the overall
%stiffness matrix
KE1 = [12 6*L -12 6*L;
6*L 4*L^2 -6*L 2*L^2;
-12 -6*L 12 -6*L;
6*L 2*L^2 -6*L 4*L^2];
KE1 = Const*KE1;
Solution
K = KE1;
KT = K;
KT(:,1) = 0;
KT(1,:) = 0;
KT(1,1) = 1;
KT(:,2) = 0;
KT(2,:) = 0;
KT(2,2) = 1;
KT(:,4) = 0;
KT(4,:) = 0;
KT(4,4) = 1;
KT(:,5) = 0;
KT(5,:) = 0;
KT(5,5) = 1;
KT(:,6) = 0;
KT(6,:) = 0;
KT(6,6) = 1;
KT
FT = [0;0; -50;0; 0;0];
d = inv(KT)*FT
F = K*d Fixed Ended Beam with Point Load Example
%Data
E = 2.1E5; % N/mm^2
L = 6000; % length in mm
I = 78E6; % mm^4
Elemental Stiffness Matrix
Const = (E*I)/(L^3);
%Since we only have one element this is the overall
%stiffness matrix
KE1 = [12 6*L -12 6*L;
6*L 4*L^2 -6*L 2*L^2;
-12 -6*L 12 -6*L;
6*L 2*L^2 -6*L 4*L^2];
KE1 = Const*KE1;
Solution
K = KE1;
KT = K;
KT(:,1) = 0;
KT(1,:) = 0;
KT(1,1) = 1;
KT(:,2) = 0;
KT(2,:) = 0;
KT(2,2) = 1;
KT(:,4) = 0;
KT(4,:) = 0;
KT(4,4) = 1;
KT(:,5) = 0;
KT(5,:) = 0;
KT(5,5) = 1;
KT(:,6) = 0;
KT(6,:) = 0;
KT(6,6) = 1;
KT
FT = [0;0; -50;0; 0;0];
d = inv(KT)*FT
F = K*d #matlab, #finiteelementanalysis, #fixedendedbeam, #pointload MATLAB Answers — New Questions
Why SIMULINK circuit and SIMCAPE circuit don’t give same results?
Hello Community!!
I’m trying to simulate a T-Type NPC PFC rectifier (yes, I know here at MATLAB exchange we have the VIENNA example but that is a Y-switch Rectifier…just saying~), I designed the 12 switch T-NPC exactly the same (valies and all) on each platform: SIMULINK and SIMSCAPE (attached).
I assume both approaches should have the same way to solve and generate the same result waveforms but as you might see on both of them the resuls are not even close.
Am I doing something wrong with SIMSCAPE that makes this difference? The circuit in SIMULINK is satisfactory, is it possibole to migrate it to SIMSCAPE somehow with some App (just to confirm I didn’t make a mistake on it)?
ThanksHello Community!!
I’m trying to simulate a T-Type NPC PFC rectifier (yes, I know here at MATLAB exchange we have the VIENNA example but that is a Y-switch Rectifier…just saying~), I designed the 12 switch T-NPC exactly the same (valies and all) on each platform: SIMULINK and SIMSCAPE (attached).
I assume both approaches should have the same way to solve and generate the same result waveforms but as you might see on both of them the resuls are not even close.
Am I doing something wrong with SIMSCAPE that makes this difference? The circuit in SIMULINK is satisfactory, is it possibole to migrate it to SIMSCAPE somehow with some App (just to confirm I didn’t make a mistake on it)?
Thanks Hello Community!!
I’m trying to simulate a T-Type NPC PFC rectifier (yes, I know here at MATLAB exchange we have the VIENNA example but that is a Y-switch Rectifier…just saying~), I designed the 12 switch T-NPC exactly the same (valies and all) on each platform: SIMULINK and SIMSCAPE (attached).
I assume both approaches should have the same way to solve and generate the same result waveforms but as you might see on both of them the resuls are not even close.
Am I doing something wrong with SIMSCAPE that makes this difference? The circuit in SIMULINK is satisfactory, is it possibole to migrate it to SIMSCAPE somehow with some App (just to confirm I didn’t make a mistake on it)?
Thanks t-type npc pfc, t-npc MATLAB Answers — New Questions