Month: January 2025
About converting Spice model to Simscape
I used the command subcircuit2ssc to convert a Spice model for the power diode to Simscape, and an error appears:
Error using subcircuit2ssc
Netlist is not supported. No valid subcircuits found.
The power diode Spice file is as follows:
.MODEL DRFN10RSM2STL1 D
+ IS=192.49E-12
+ N=1.1157
+ RS=4.3285E-3
+ IKF=98.758E-3
+ EG=0.88
+ CJO=168.00E-12
+ M=0.3114
+ VJ=0.5
+ ISR=539.76E-12
+ NR=1.95
+ BV=200
+ TT=26.548E-9
+ TIKF=0.012
I have succesfully converted a power MOSFET model from Spice to Simscape. I wonder why this does not work for diode. Thanks!I used the command subcircuit2ssc to convert a Spice model for the power diode to Simscape, and an error appears:
Error using subcircuit2ssc
Netlist is not supported. No valid subcircuits found.
The power diode Spice file is as follows:
.MODEL DRFN10RSM2STL1 D
+ IS=192.49E-12
+ N=1.1157
+ RS=4.3285E-3
+ IKF=98.758E-3
+ EG=0.88
+ CJO=168.00E-12
+ M=0.3114
+ VJ=0.5
+ ISR=539.76E-12
+ NR=1.95
+ BV=200
+ TT=26.548E-9
+ TIKF=0.012
I have succesfully converted a power MOSFET model from Spice to Simscape. I wonder why this does not work for diode. Thanks! I used the command subcircuit2ssc to convert a Spice model for the power diode to Simscape, and an error appears:
Error using subcircuit2ssc
Netlist is not supported. No valid subcircuits found.
The power diode Spice file is as follows:
.MODEL DRFN10RSM2STL1 D
+ IS=192.49E-12
+ N=1.1157
+ RS=4.3285E-3
+ IKF=98.758E-3
+ EG=0.88
+ CJO=168.00E-12
+ M=0.3114
+ VJ=0.5
+ ISR=539.76E-12
+ NR=1.95
+ BV=200
+ TT=26.548E-9
+ TIKF=0.012
I have succesfully converted a power MOSFET model from Spice to Simscape. I wonder why this does not work for diode. Thanks! spice, model, simscape, convert, power diode, subcircuit2ssc MATLAB Answers — New Questions
XML EDIT attribute value
My question might seem dumb but I can’t seem to find the answer: How can I edit certain values on an xml file that already exists?
I want to edit all the attributes values with values coming from an excel sheet. Is that possible?
Thanks!My question might seem dumb but I can’t seem to find the answer: How can I edit certain values on an xml file that already exists?
I want to edit all the attributes values with values coming from an excel sheet. Is that possible?
Thanks! My question might seem dumb but I can’t seem to find the answer: How can I edit certain values on an xml file that already exists?
I want to edit all the attributes values with values coming from an excel sheet. Is that possible?
Thanks! xml, xmledit MATLAB Answers — New Questions
matlab calculation area circular
I have a signal and want to calculate the area. The problem is that i want to make a loop with decimal step, because the length is 1189,58
Any ideas how to proceed with the loop?I have a signal and want to calculate the area. The problem is that i want to make a loop with decimal step, because the length is 1189,58
Any ideas how to proceed with the loop? I have a signal and want to calculate the area. The problem is that i want to make a loop with decimal step, because the length is 1189,58
Any ideas how to proceed with the loop? range, area MATLAB Answers — New Questions
Is it possible to use MATLAB on slave computer/device for communication to host computer via serial MODBUS (RTU)
Can I communicate with the host/master via serial port (MODBUS ASCII/RTU) using MATLAB on the slave computer, i.e. I need to wait for a request from the host/master, receive it when it comes and send back the requested data to the host. I found how this can implemented for MODBUS TCP/IP, but I did not find how to implement that for MODBUS ASCII/RTU (RS232, RS485). All MATLAB functions for serial port communication seem to be for the case when the code runs on the host computer. My MATLAB code runs on the slave device (processor/computer which controls the analytical instrument) and I need it to send the data when requested to the host (SCADA).Can I communicate with the host/master via serial port (MODBUS ASCII/RTU) using MATLAB on the slave computer, i.e. I need to wait for a request from the host/master, receive it when it comes and send back the requested data to the host. I found how this can implemented for MODBUS TCP/IP, but I did not find how to implement that for MODBUS ASCII/RTU (RS232, RS485). All MATLAB functions for serial port communication seem to be for the case when the code runs on the host computer. My MATLAB code runs on the slave device (processor/computer which controls the analytical instrument) and I need it to send the data when requested to the host (SCADA). Can I communicate with the host/master via serial port (MODBUS ASCII/RTU) using MATLAB on the slave computer, i.e. I need to wait for a request from the host/master, receive it when it comes and send back the requested data to the host. I found how this can implemented for MODBUS TCP/IP, but I did not find how to implement that for MODBUS ASCII/RTU (RS232, RS485). All MATLAB functions for serial port communication seem to be for the case when the code runs on the host computer. My MATLAB code runs on the slave device (processor/computer which controls the analytical instrument) and I need it to send the data when requested to the host (SCADA). serial port, modbus, modbus ascii, modbus rtu, modbus slave, modbus host, rs485, rs232 MATLAB Answers — New Questions
Convergence path error,Variables of this type do not support indexing with points.
I have a new problem, I obtain aspen convergence in the connection operation between aspen and matlab, my code is:
Conv = aspen.Tree.FindNode("DataResults SummaryRun-StatusOutputPER_ERROR");
I also found the corresponding path in aspen, but the code is wrong, At the same time, I have checked that CSDN does not support indexing with points for variables of this type, but when I change the code to:
Conv = Aspen.Tree.FindNode("DataResults SummaryRun-StatusOutputPER_ERROR");
ConvValue = Conv.Value;
I still get an errorI have a new problem, I obtain aspen convergence in the connection operation between aspen and matlab, my code is:
Conv = aspen.Tree.FindNode("DataResults SummaryRun-StatusOutputPER_ERROR");
I also found the corresponding path in aspen, but the code is wrong, At the same time, I have checked that CSDN does not support indexing with points for variables of this type, but when I change the code to:
Conv = Aspen.Tree.FindNode("DataResults SummaryRun-StatusOutputPER_ERROR");
ConvValue = Conv.Value;
I still get an error I have a new problem, I obtain aspen convergence in the connection operation between aspen and matlab, my code is:
Conv = aspen.Tree.FindNode("DataResults SummaryRun-StatusOutputPER_ERROR");
I also found the corresponding path in aspen, but the code is wrong, At the same time, I have checked that CSDN does not support indexing with points for variables of this type, but when I change the code to:
Conv = Aspen.Tree.FindNode("DataResults SummaryRun-StatusOutputPER_ERROR");
ConvValue = Conv.Value;
I still get an error aspen,matlab MATLAB Answers — New Questions
Closing windows CMD window after executing system and run through a certain algorithm
I want to use ‘system’ to open another software in cmd as well as forming a java socket between them to allow exchanging datas for calculation, as shown in the code below
% command to execute in cmd to form socket
commandString = strcat(‘"’, this.FreeFlyerPath, ‘FreeFlyer.exe"’, …
‘ -r -mp "’, this.MissionPlanPath, ‘sample.MissionPlan"’, …
sprintf(‘ -ui %d -ui %d -ui %s &’, portNum(1), portNum(2), this.terminationCode));
system( commandString );
%
%
%
%
% some algorithms
%
%
%
% how to close the cmd?
However, the function has to be looped multiple times, that means the cmd windows keep popping out like a virus without exiting. I tried system(‘exit’) and it does not work. May I know the correct way to close the cmd window after executed the function?I want to use ‘system’ to open another software in cmd as well as forming a java socket between them to allow exchanging datas for calculation, as shown in the code below
% command to execute in cmd to form socket
commandString = strcat(‘"’, this.FreeFlyerPath, ‘FreeFlyer.exe"’, …
‘ -r -mp "’, this.MissionPlanPath, ‘sample.MissionPlan"’, …
sprintf(‘ -ui %d -ui %d -ui %s &’, portNum(1), portNum(2), this.terminationCode));
system( commandString );
%
%
%
%
% some algorithms
%
%
%
% how to close the cmd?
However, the function has to be looped multiple times, that means the cmd windows keep popping out like a virus without exiting. I tried system(‘exit’) and it does not work. May I know the correct way to close the cmd window after executed the function? I want to use ‘system’ to open another software in cmd as well as forming a java socket between them to allow exchanging datas for calculation, as shown in the code below
% command to execute in cmd to form socket
commandString = strcat(‘"’, this.FreeFlyerPath, ‘FreeFlyer.exe"’, …
‘ -r -mp "’, this.MissionPlanPath, ‘sample.MissionPlan"’, …
sprintf(‘ -ui %d -ui %d -ui %s &’, portNum(1), portNum(2), this.terminationCode));
system( commandString );
%
%
%
%
% some algorithms
%
%
%
% how to close the cmd?
However, the function has to be looped multiple times, that means the cmd windows keep popping out like a virus without exiting. I tried system(‘exit’) and it does not work. May I know the correct way to close the cmd window after executed the function? system, cmd, exit MATLAB Answers — New Questions
Problem in applying Genetic algorithm solver in matlab while solving the electric bus scheduling problem
I am using a Genetic Algorithm (GA) solver in MATLAB to solve the electric bus scheduling problem. The objective function is designed to minimize the cost of electric buses and chargers while incorporating vehicle flow and charging constraints. However, when I apply the solver, it seems to ignore the charging constraints. It only outputs the number of electric buses along with their schedules, without assigning any buses to chargers. The output for chargers consistently shows a value of zero. When I tested the same dataset using CPLEX, it successfully assigned electric buses to chargers. How can I resolve this issue?
% Solver options
options = optimoptions(‘ga’, …
‘Display’, ‘iter’, … % Display iteration details
‘PlotFcn’, ‘gaplotbestf’, … % Plot GA progress
‘MaxTime’, 5000, … % Maximum runtime in seconds
‘PopulationSize’, 100, … % GA population size
‘CrossoverFraction’, 0.8); % Fraction for crossover
% Solve the optimization problem
[sol, fval, exitflag, output] = solve(Busschedulling_A, ‘Solver’, ‘ga’, ‘Options’, options);I am using a Genetic Algorithm (GA) solver in MATLAB to solve the electric bus scheduling problem. The objective function is designed to minimize the cost of electric buses and chargers while incorporating vehicle flow and charging constraints. However, when I apply the solver, it seems to ignore the charging constraints. It only outputs the number of electric buses along with their schedules, without assigning any buses to chargers. The output for chargers consistently shows a value of zero. When I tested the same dataset using CPLEX, it successfully assigned electric buses to chargers. How can I resolve this issue?
% Solver options
options = optimoptions(‘ga’, …
‘Display’, ‘iter’, … % Display iteration details
‘PlotFcn’, ‘gaplotbestf’, … % Plot GA progress
‘MaxTime’, 5000, … % Maximum runtime in seconds
‘PopulationSize’, 100, … % GA population size
‘CrossoverFraction’, 0.8); % Fraction for crossover
% Solve the optimization problem
[sol, fval, exitflag, output] = solve(Busschedulling_A, ‘Solver’, ‘ga’, ‘Options’, options); I am using a Genetic Algorithm (GA) solver in MATLAB to solve the electric bus scheduling problem. The objective function is designed to minimize the cost of electric buses and chargers while incorporating vehicle flow and charging constraints. However, when I apply the solver, it seems to ignore the charging constraints. It only outputs the number of electric buses along with their schedules, without assigning any buses to chargers. The output for chargers consistently shows a value of zero. When I tested the same dataset using CPLEX, it successfully assigned electric buses to chargers. How can I resolve this issue?
% Solver options
options = optimoptions(‘ga’, …
‘Display’, ‘iter’, … % Display iteration details
‘PlotFcn’, ‘gaplotbestf’, … % Plot GA progress
‘MaxTime’, 5000, … % Maximum runtime in seconds
‘PopulationSize’, 100, … % GA population size
‘CrossoverFraction’, 0.8); % Fraction for crossover
% Solve the optimization problem
[sol, fval, exitflag, output] = solve(Busschedulling_A, ‘Solver’, ‘ga’, ‘Options’, options); genetic algorithm, matlab, optimization, programming MATLAB Answers — New Questions
Teams Splits Recording and Transcription Settings for Meetings and Events
Separate Teams Policies Govern Recording and Transcription from February 2025
In a sensible decision announced in two Microsoft 365 message center posts on 3 January 2025, Microsoft plans to use separate Teams recording and transcription policies for meeting and events. Until now, the same org-wide meeting policy governed both kinds of gatherings. From late February 2025, all forms of meetings will use the current meeting policy while events will use settings in the Teams event policy. Separate settings are available to control recording and transcription in webinar and town hall events.
The relevant message center posts are MC971032 (recording) Microsoft 365 roadmap item 473887, and MC971031 (transcription), Microsoft 365 roadmap item 473886.
Managing Teams Recording and Transcription Policies
The settings for Teams recording and transcription policies can be managed through the Teams admin center (Figure 1) or with PowerShell. The settings dictate whether meeting organizers can record and transcribe their events.
The new recording and transcription settings are not currently available in the Teams admin center. In the interim, you can use PowerShell to update the default Teams event policy or configure new Teams event policies. For example, this example of using the Get-CsTeamsEventsPolicy cmdlet finds all Teams event policies in the tenant and outputs the value of the settings used to control recording and transcription for town hall and webinar events:
Get-CsTeamsEventsPolicy | Format-Table Identity, RecordingForTownhall, TranscriptionForTownHall, RecordingForWebinar, TranscriptionForWebinar -AutoSize Identity RecordingForTownhall TranscriptionForTownhall RecordingForWebinar TranscriptionForWebinar -------- -------------------- ------------------------ ------------------- ----------------------- Global Enabled Enabled Enabled Enabled Tag:WebinarOrganizers Enabled Enabled Enabled Enabled
The values shown above are the default. To disable a setting, run the Set-CsTeamsEventsPolicy cmdlet. For example:
Set-CsTeamsEventsPolicy -Identity Global -RecordingForTownHall Disabled
When updating Teams event policies, make sure that you use a current version of the Microsoft Teams PowerShell module (I used V6.7 for the commands shown above).
Transcription Default Setting Changing to On
There’s no doubt that meeting transcriptions are very useful, even if you don’t have Microsoft 365 Copilot or Teams Premium licenses to generate intelligent recaps from transcripts.
Reflecting the value of transcripts, Microsoft will introduce another change in February 2025 to enable transcripts for meetings as the default (currently, the setting is disabled). The change will apply to new tenants and any existing tenants if they don’t have customized meeting policies. In other words, if you have an existing Microsoft 365 tenant and have never changed the meeting policy, the transcription setting shown in Figure 1 will change from Off to On.
The update is documented in message center post MC973519 (7 January 2025, Microsoft 365 roadmap item 468282). Microsoft says that the change to the default transcription setting will make it consistent with the recording setting and notes that the change “is designed to streamline the adoption of transcription and enhance the use of all AI features.” There’s no point in having premium functionality ready to process transcripts if transcription is disabled.
Face and Voice Enrollment
Another change in this area is documented in MC912707 (updated 20 December 2024, Microsoft 365 roadmap item 413708), which governs voice and face profile enrolment for meetings held in rooms equipped with Teams Rooms devices. Microsoft plans to enable voice and face profile enrolment by default from mid-February 2025.
The problem that Microsoft is trying to solve is to differentiate between individuals in a meeting room so that contributions can be correctly attributed to the right person in the transcript. By enrolling their voice and face profile, users make it easier for Teams to identify them using technologies like facial and vocal recognition. See the Microsoft documentation for more information.
Some organizations aren’t too keen on users enrolling voice and face profiles. If you’re in this situation, you can disable enrolment using the Set-CsTeamsAIPolicy cmdlet. The default values are revealed with Get-CsTeamsAIPolicy:
Get-CsTeamsAIPolicy Identity EnrollFace EnrollVoice -------- ---------- ----------- Global Enabled Enabled
To disable the settings and prevent users enrolling a profile, run:
Set-CsTeamsAIPolicy -Identity Global -EnrollFace Disabled -EnrollVoice Disabled
Many Changes Around Transcription
Microsoft has been busy around meeting transcription over the last year. The activity has included moving Teams transcripts to OneDrive to make storage consistent and imposing tighter control over transcripts. Both steps were necessary predecessors before making meeting transcription the default. Not everyone will love the changes Microsoft is making to make transcription more pervasive and accurate. It’s your tenant, so take charge and decide what policy defaults you think are best to use.
Learn about using Teams and the rest of Microsoft 365 by subscribing to the Office 365 for IT Pros eBook. Use our experience to understand what’s important and how best to protect your tenant.
Warning: Parameter object’s DataType property has been set while its Value is not double precision.
I have this warnings in matlab
Warning: Parameter object’s DataType property has been set while its Value is not double precision. Converting Value to real-world value (double precision).
I use .m file when declare parameter
and delare like this
Y.Value = [fi([0,10,10,0,0,0,0,0,0,0], 1, 16, 0.01, 0)];
When I enterend Y Value in command Window say like this
Parameter with properties:
Value: [0 10 10 0 0 0 0 0 0 0]
CoderInfo: [1×1 Simulink.CoderInfo]
Description: ‘-‘
DataType: ‘fixdt(0,16,0.01,0)’
Min: []
Max: []
Unit: ”
Complexity: ‘real’
Dimensions: [1 10]
Why this warning happens?I have this warnings in matlab
Warning: Parameter object’s DataType property has been set while its Value is not double precision. Converting Value to real-world value (double precision).
I use .m file when declare parameter
and delare like this
Y.Value = [fi([0,10,10,0,0,0,0,0,0,0], 1, 16, 0.01, 0)];
When I enterend Y Value in command Window say like this
Parameter with properties:
Value: [0 10 10 0 0 0 0 0 0 0]
CoderInfo: [1×1 Simulink.CoderInfo]
Description: ‘-‘
DataType: ‘fixdt(0,16,0.01,0)’
Min: []
Max: []
Unit: ”
Complexity: ‘real’
Dimensions: [1 10]
Why this warning happens? I have this warnings in matlab
Warning: Parameter object’s DataType property has been set while its Value is not double precision. Converting Value to real-world value (double precision).
I use .m file when declare parameter
and delare like this
Y.Value = [fi([0,10,10,0,0,0,0,0,0,0], 1, 16, 0.01, 0)];
When I enterend Y Value in command Window say like this
Parameter with properties:
Value: [0 10 10 0 0 0 0 0 0 0]
CoderInfo: [1×1 Simulink.CoderInfo]
Description: ‘-‘
DataType: ‘fixdt(0,16,0.01,0)’
Min: []
Max: []
Unit: ”
Complexity: ‘real’
Dimensions: [1 10]
Why this warning happens? simulink, matlab MATLAB Answers — New Questions
How to stop command window from pasting in previous commands?
I’ve been encountering a strange issue with my command windows as of recent. For some reason whenever I type something in, it will provide to paste previous prompts from the window about 20 times over. This results in the workspace becoming unusable. Does anyone know what might be causing this? I’m new to the system so its difficult for me to troubleshoot.I’ve been encountering a strange issue with my command windows as of recent. For some reason whenever I type something in, it will provide to paste previous prompts from the window about 20 times over. This results in the workspace becoming unusable. Does anyone know what might be causing this? I’m new to the system so its difficult for me to troubleshoot. I’ve been encountering a strange issue with my command windows as of recent. For some reason whenever I type something in, it will provide to paste previous prompts from the window about 20 times over. This results in the workspace becoming unusable. Does anyone know what might be causing this? I’m new to the system so its difficult for me to troubleshoot. help, matlab MATLAB Answers — New Questions
accessIntervals Function: Subscripting into a Table Using One Subscript Error
Problem Description:
I am working on a MATLAB project involving the Satellite Communications Toolbox. My script uses the accessIntervals function to compute access intervals for satellites and ground stations. However, I consistently encounter the following error:
sql
Copy code
Subscripting into a table using one subscript (as in t(i)) is not supported. Specify a row subscript and a variable subscript, as in t(rows,vars). To select variables, use t(:,i) or for one variable t.(i). To select rows, use t(i,:).
Steps to Reproduce:
I created a satellite scenario with the following setup:matlabCopy codestartTime = datetime(2024, 1, 6, 23, 23, 0);
stopTime = startTime + hours(24);
sampleTime = 60;
sc = satelliteScenario(startTime, stopTime, sampleTime);
sat = walkerDelta(sc, 570e3 + 6378.14e3, 70, 720, 36, 1, ArgumentOfLatitude=15, Name="Starlink");
gs = groundStation(sc, "Name", "Test Station", "Latitude", -35.40139, "Longitude", 148.98167);
ac = access(sat, gs);
I attempted to call accessIntervals for the Access object:matlabCopy codeTest = accessIntervals(ac(1));
The error occurs for all Access objects (ac).
Debugging Steps Taken:
I confirmed the Access objects (ac) are valid and properly initialized:matlabCopy codeAccess Object 1:
Access with properties:
Sequence: [1 721]
LineWidth: 3
LineColor: [0.3922 0.8314 0.0745]
The error persists for all Access objects.
Questions:
Is this a known issue with accessIntervals or the Satellite Communications Toolbox?
How can I resolve or work around this error to compute access intervals?
Are there alternative methods to compute satellite-ground station access intervals if accessIntervals cannot be used?
Environment: MatlabonlineProblem Description:
I am working on a MATLAB project involving the Satellite Communications Toolbox. My script uses the accessIntervals function to compute access intervals for satellites and ground stations. However, I consistently encounter the following error:
sql
Copy code
Subscripting into a table using one subscript (as in t(i)) is not supported. Specify a row subscript and a variable subscript, as in t(rows,vars). To select variables, use t(:,i) or for one variable t.(i). To select rows, use t(i,:).
Steps to Reproduce:
I created a satellite scenario with the following setup:matlabCopy codestartTime = datetime(2024, 1, 6, 23, 23, 0);
stopTime = startTime + hours(24);
sampleTime = 60;
sc = satelliteScenario(startTime, stopTime, sampleTime);
sat = walkerDelta(sc, 570e3 + 6378.14e3, 70, 720, 36, 1, ArgumentOfLatitude=15, Name="Starlink");
gs = groundStation(sc, "Name", "Test Station", "Latitude", -35.40139, "Longitude", 148.98167);
ac = access(sat, gs);
I attempted to call accessIntervals for the Access object:matlabCopy codeTest = accessIntervals(ac(1));
The error occurs for all Access objects (ac).
Debugging Steps Taken:
I confirmed the Access objects (ac) are valid and properly initialized:matlabCopy codeAccess Object 1:
Access with properties:
Sequence: [1 721]
LineWidth: 3
LineColor: [0.3922 0.8314 0.0745]
The error persists for all Access objects.
Questions:
Is this a known issue with accessIntervals or the Satellite Communications Toolbox?
How can I resolve or work around this error to compute access intervals?
Are there alternative methods to compute satellite-ground station access intervals if accessIntervals cannot be used?
Environment: Matlabonline Problem Description:
I am working on a MATLAB project involving the Satellite Communications Toolbox. My script uses the accessIntervals function to compute access intervals for satellites and ground stations. However, I consistently encounter the following error:
sql
Copy code
Subscripting into a table using one subscript (as in t(i)) is not supported. Specify a row subscript and a variable subscript, as in t(rows,vars). To select variables, use t(:,i) or for one variable t.(i). To select rows, use t(i,:).
Steps to Reproduce:
I created a satellite scenario with the following setup:matlabCopy codestartTime = datetime(2024, 1, 6, 23, 23, 0);
stopTime = startTime + hours(24);
sampleTime = 60;
sc = satelliteScenario(startTime, stopTime, sampleTime);
sat = walkerDelta(sc, 570e3 + 6378.14e3, 70, 720, 36, 1, ArgumentOfLatitude=15, Name="Starlink");
gs = groundStation(sc, "Name", "Test Station", "Latitude", -35.40139, "Longitude", 148.98167);
ac = access(sat, gs);
I attempted to call accessIntervals for the Access object:matlabCopy codeTest = accessIntervals(ac(1));
The error occurs for all Access objects (ac).
Debugging Steps Taken:
I confirmed the Access objects (ac) are valid and properly initialized:matlabCopy codeAccess Object 1:
Access with properties:
Sequence: [1 721]
LineWidth: 3
LineColor: [0.3922 0.8314 0.0745]
The error persists for all Access objects.
Questions:
Is this a known issue with accessIntervals or the Satellite Communications Toolbox?
How can I resolve or work around this error to compute access intervals?
Are there alternative methods to compute satellite-ground station access intervals if accessIntervals cannot be used?
Environment: Matlabonline accessintervals satellite toolbox satellite scenar, table indexing, error handling MATLAB Answers — New Questions
The lane markings appears at the right side of each road, but according to the official tutorial it should be at the road center.
the picture is below.I can’t find how to set the lane markings(the yellow lane in the picture) to the road center it needed. thanks for your warm help.the picture is below.I can’t find how to set the lane markings(the yellow lane in the picture) to the road center it needed. thanks for your warm help. the picture is below.I can’t find how to set the lane markings(the yellow lane in the picture) to the road center it needed. thanks for your warm help. driving scenario designer MATLAB Answers — New Questions
Edit Code Initialization under Mask editor
I am creating the mask for my simulink block and I need to add the Initiallization code to it. Unfortumatelly I can’t edit (add) code within the mask editor; it’s grayed and not editable, disabled.
How can I access this, and add the initialization code to it?
Thank you.I am creating the mask for my simulink block and I need to add the Initiallization code to it. Unfortumatelly I can’t edit (add) code within the mask editor; it’s grayed and not editable, disabled.
How can I access this, and add the initialization code to it?
Thank you. I am creating the mask for my simulink block and I need to add the Initiallization code to it. Unfortumatelly I can’t edit (add) code within the mask editor; it’s grayed and not editable, disabled.
How can I access this, and add the initialization code to it?
Thank you. initialization under mask editor MATLAB Answers — New Questions
Is it possible to generate code for cloud computing platforms (i.e. Azure, AWS)?
I would like to generate code from a Simulink model in a cloud computing platform. Is it possible?
Other option: is it possible to convert the generated C code from Simulink in other language (i.e. Python, Julia, R)?I would like to generate code from a Simulink model in a cloud computing platform. Is it possible?
Other option: is it possible to convert the generated C code from Simulink in other language (i.e. Python, Julia, R)? I would like to generate code from a Simulink model in a cloud computing platform. Is it possible?
Other option: is it possible to convert the generated C code from Simulink in other language (i.e. Python, Julia, R)? cloud, code generation, simulink, python MATLAB Answers — New Questions
Extract and sort size of matrix where in the cell
clc;clear;close all
im= [0 0 0 0 0 0 0 0 0 0
0 0 1 1 1 1 1 1 0 0
0 0 1 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0];
cc=bwconncomp(im);
for i=1:cc.NumObjects
CC{i}=cc.PixelIdxList{i}
end
Size=zeros(1,cc.NumObjects);
for j=1:cc.NumObjects
Size(:,i)=size(cell2mat(CC(j)))
endclc;clear;close all
im= [0 0 0 0 0 0 0 0 0 0
0 0 1 1 1 1 1 1 0 0
0 0 1 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0];
cc=bwconncomp(im);
for i=1:cc.NumObjects
CC{i}=cc.PixelIdxList{i}
end
Size=zeros(1,cc.NumObjects);
for j=1:cc.NumObjects
Size(:,i)=size(cell2mat(CC(j)))
end clc;clear;close all
im= [0 0 0 0 0 0 0 0 0 0
0 0 1 1 1 1 1 1 0 0
0 0 1 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0];
cc=bwconncomp(im);
for i=1:cc.NumObjects
CC{i}=cc.PixelIdxList{i}
end
Size=zeros(1,cc.NumObjects);
for j=1:cc.NumObjects
Size(:,i)=size(cell2mat(CC(j)))
end for loop MATLAB Answers — New Questions
How to calculate the PSNR of video sequence?
Hi there,
I want to calculate the PSNR value between two videos. One video is original and another one is watermarked video. The watermarked video has some watermarked frame. I have calculated PSNR of each frame one at a time of both of the videos, and calsulate the average of it, but unfortunately I get the "Inf" value of PSNR.
Again, I have also tried to calculate the PSNR of exactly two videos. As a result, I got the PSNR of 40 dB. In fact, the result must be 99.99
Any help must be appreciated.
Thanks in advance.
The code I have written to calculate the PSNR of two idential videos
clc;
output_folder = ‘D:Matlab book and filesSLTAkiyo_frames_journal’;
vidObj1 = VideoReader(‘akiyo_cif_x264.mp4’);
vidObj2 = VideoReader(‘akiyo_cif_x264_Copy.mp4’);
EnumFrames=0;
Extframe = cell(1,300) ;
frame = cell(1,300) ;
numFrames1 = 0;
numFrames2 = 0;
while hasFrame(vidObj1)
F1 = readFrame(vidObj1);
numFrames1 = numFrames1 + 1;
frame{numFrames1} = F ;
numFrames1
while hasFrame(vidObj2)
F2 = readFrame(vidObj2);
numFrames2 = numFrames2 + 1;
Extframe{numFrames2}=F2;
end
numFrames2
for i= 1:300
Extframe{i}= getframe;
frame{i}= getframe;
fprintf ("The PSNR of frame %d = %.2f n", i , psnr(frame2im(Extframe{i}),frame2im(frame{i})))
end
OUTPUT
The PSNR of frame 1 = Inf
The PSNR of frame 2 = Inf
The PSNR of frame 3 = Inf
The PSNR of frame 4 = Inf
The PSNR of frame 5 = Inf
The PSNR of frame 6 = Inf
The PSNR of frame 7 = Inf
The PSNR of frame 8 = Inf
The PSNR of frame 9 = Inf
The PSNR of frame 10 = Inf
……………………………………..
………………………………………
……………………………………..
The PSNR of frame 300 = InfHi there,
I want to calculate the PSNR value between two videos. One video is original and another one is watermarked video. The watermarked video has some watermarked frame. I have calculated PSNR of each frame one at a time of both of the videos, and calsulate the average of it, but unfortunately I get the "Inf" value of PSNR.
Again, I have also tried to calculate the PSNR of exactly two videos. As a result, I got the PSNR of 40 dB. In fact, the result must be 99.99
Any help must be appreciated.
Thanks in advance.
The code I have written to calculate the PSNR of two idential videos
clc;
output_folder = ‘D:Matlab book and filesSLTAkiyo_frames_journal’;
vidObj1 = VideoReader(‘akiyo_cif_x264.mp4’);
vidObj2 = VideoReader(‘akiyo_cif_x264_Copy.mp4’);
EnumFrames=0;
Extframe = cell(1,300) ;
frame = cell(1,300) ;
numFrames1 = 0;
numFrames2 = 0;
while hasFrame(vidObj1)
F1 = readFrame(vidObj1);
numFrames1 = numFrames1 + 1;
frame{numFrames1} = F ;
numFrames1
while hasFrame(vidObj2)
F2 = readFrame(vidObj2);
numFrames2 = numFrames2 + 1;
Extframe{numFrames2}=F2;
end
numFrames2
for i= 1:300
Extframe{i}= getframe;
frame{i}= getframe;
fprintf ("The PSNR of frame %d = %.2f n", i , psnr(frame2im(Extframe{i}),frame2im(frame{i})))
end
OUTPUT
The PSNR of frame 1 = Inf
The PSNR of frame 2 = Inf
The PSNR of frame 3 = Inf
The PSNR of frame 4 = Inf
The PSNR of frame 5 = Inf
The PSNR of frame 6 = Inf
The PSNR of frame 7 = Inf
The PSNR of frame 8 = Inf
The PSNR of frame 9 = Inf
The PSNR of frame 10 = Inf
……………………………………..
………………………………………
……………………………………..
The PSNR of frame 300 = Inf Hi there,
I want to calculate the PSNR value between two videos. One video is original and another one is watermarked video. The watermarked video has some watermarked frame. I have calculated PSNR of each frame one at a time of both of the videos, and calsulate the average of it, but unfortunately I get the "Inf" value of PSNR.
Again, I have also tried to calculate the PSNR of exactly two videos. As a result, I got the PSNR of 40 dB. In fact, the result must be 99.99
Any help must be appreciated.
Thanks in advance.
The code I have written to calculate the PSNR of two idential videos
clc;
output_folder = ‘D:Matlab book and filesSLTAkiyo_frames_journal’;
vidObj1 = VideoReader(‘akiyo_cif_x264.mp4’);
vidObj2 = VideoReader(‘akiyo_cif_x264_Copy.mp4’);
EnumFrames=0;
Extframe = cell(1,300) ;
frame = cell(1,300) ;
numFrames1 = 0;
numFrames2 = 0;
while hasFrame(vidObj1)
F1 = readFrame(vidObj1);
numFrames1 = numFrames1 + 1;
frame{numFrames1} = F ;
numFrames1
while hasFrame(vidObj2)
F2 = readFrame(vidObj2);
numFrames2 = numFrames2 + 1;
Extframe{numFrames2}=F2;
end
numFrames2
for i= 1:300
Extframe{i}= getframe;
frame{i}= getframe;
fprintf ("The PSNR of frame %d = %.2f n", i , psnr(frame2im(Extframe{i}),frame2im(frame{i})))
end
OUTPUT
The PSNR of frame 1 = Inf
The PSNR of frame 2 = Inf
The PSNR of frame 3 = Inf
The PSNR of frame 4 = Inf
The PSNR of frame 5 = Inf
The PSNR of frame 6 = Inf
The PSNR of frame 7 = Inf
The PSNR of frame 8 = Inf
The PSNR of frame 9 = Inf
The PSNR of frame 10 = Inf
……………………………………..
………………………………………
……………………………………..
The PSNR of frame 300 = Inf video watermatrking, video processing, watermarking MATLAB Answers — New Questions
Why is my transformer training erroring out, with the following message “Error using trainnet (line 46)”
The full error message reads "Error using trainnet (line 46)
The number of mini-batch queue outputs (2) must match the number of network inputs plus
the number of network outputs (4)."
I’m using an arrayDatastore to pass the predictors (x2) and the targets(x2) to the transformer model. Both predictors have 410 features, one of the targets has 410 features and the other target is a scalar function.
Code to generate the dummy predictor and target data is pasted below:
%——————————————————————–
% data generation for encoder
numObs = 10;
seqLen = vocabSize;
x_enc = randi([1,10],[seqLen,numObs]);
y_enc = zeros(numObs,1);
for i = 1:numObs
idx = x_enc(1:2,i);
y_enc(i,:) = sum(x_enc(idx,i));
end
x_enc = num2cell(x_enc’,2);
y_enc = num2cell(y_enc)’;
x_1 = x_enc;
y_2 = y_enc’;
% data generation for decoder
x_series = randi([1,10],[seqLen,numObs]);
y_series = sin(rand([seqLen,numObs]));
x_dec = x_series(:,1:end)’;
y_dec = y_series(:,1:end)’;
x_dec = num2cell(x_dec,2); x_2 = x_dec;
y_dec = num2cell(y_dec,2); y_1 = y_dec;
cell_data = {}; cell_data = [cell_data x_1 x_2 y_1 y_2];
dstrain = arrayDatastore(cell_data,’OutputType’,’same’);
%——————————————————————-
cell_data is of the form:
cell_data
cell_data =
10×4 cell array
{1×410 double} {1×410 double} {1×410 double} {[ 8]}
{1×410 double} {1×410 double} {1×410 double} {[10]}
{1×410 double} {1×410 double} {1×410 double} {[13]}
{1×410 double} {1×410 double} {1×410 double} {[20]}
{1×410 double} {1×410 double} {1×410 double} {[ 7]}
{1×410 double} {1×410 double} {1×410 double} {[ 8]}
{1×410 double} {1×410 double} {1×410 double} {[17]}
{1×410 double} {1×410 double} {1×410 double} {[ 6]}
{1×410 double} {1×410 double} {1×410 double} {[11]}
{1×410 double} {1×410 double} {1×410 double} {[ 8]}
If I were to use readall(dstrain) to read the datastore, I get the same format as cell_data:
fds = readall(dstrain)
fds =
10×4 cell array
{1×410 double} {1×410 double} {1×410 double} {[ 8]}
{1×410 double} {1×410 double} {1×410 double} {[10]}
{1×410 double} {1×410 double} {1×410 double} {[13]}
{1×410 double} {1×410 double} {1×410 double} {[20]}
{1×410 double} {1×410 double} {1×410 double} {[ 7]}
{1×410 double} {1×410 double} {1×410 double} {[ 8]}
{1×410 double} {1×410 double} {1×410 double} {[17]}
{1×410 double} {1×410 double} {1×410 double} {[ 6]}
{1×410 double} {1×410 double} {1×410 double} {[11]}
{1×410 double} {1×410 double} {1×410 double} {[ 8]}
Finally, if I use minibatchqueue to create a minibatch of datastore ‘dstrain’, I get:
mbq = minibatchqueue(dstrain)
mbq =
minibatchqueue with 4 outputs and properties:
Mini-batch creation:
MiniBatchSize: 10
PartialMiniBatch: ‘return’
MiniBatchFcn: ‘collate’
PreprocessingEnvironment: ‘serial’
Outputs:
OutputCast: {‘single’ ‘single’ ‘single’ ‘single’}
OutputAsDlarray: [1 1 1 1]
MiniBatchFormat: {” ” ” ”}
OutputEnvironment: {‘auto’ ‘auto’ ‘auto’ ‘auto’}
As you can see, there are four outputs for the minibatch, which appears to contradict the original error message that there are only two minibatchqueue outputs
Also to confirm, i double checked the transformer input output structure:
net
net =
dlnetwork with properties:
Layers: [64×1 nnet.cnn.layer.Layer]
Connections: [1714×2 table]
Learnables: [110×3 table]
State: [0×3 table]
InputNames: {‘in_enc’ ‘in_dec’}
OutputNames: {‘decoder_out’ ‘fc_13’}
Initialized: 1
View summary with summary.
which shows two inputs and two outputs.
Could someone point me to the mistake I’m making here (likely with the datastore format) – it seems that during batching, the model is only choosing two of the cell columns from cell_data/dstrain for the input and output, rather than all four and its not clear why…thanks in advance for your help!
CGThe full error message reads "Error using trainnet (line 46)
The number of mini-batch queue outputs (2) must match the number of network inputs plus
the number of network outputs (4)."
I’m using an arrayDatastore to pass the predictors (x2) and the targets(x2) to the transformer model. Both predictors have 410 features, one of the targets has 410 features and the other target is a scalar function.
Code to generate the dummy predictor and target data is pasted below:
%——————————————————————–
% data generation for encoder
numObs = 10;
seqLen = vocabSize;
x_enc = randi([1,10],[seqLen,numObs]);
y_enc = zeros(numObs,1);
for i = 1:numObs
idx = x_enc(1:2,i);
y_enc(i,:) = sum(x_enc(idx,i));
end
x_enc = num2cell(x_enc’,2);
y_enc = num2cell(y_enc)’;
x_1 = x_enc;
y_2 = y_enc’;
% data generation for decoder
x_series = randi([1,10],[seqLen,numObs]);
y_series = sin(rand([seqLen,numObs]));
x_dec = x_series(:,1:end)’;
y_dec = y_series(:,1:end)’;
x_dec = num2cell(x_dec,2); x_2 = x_dec;
y_dec = num2cell(y_dec,2); y_1 = y_dec;
cell_data = {}; cell_data = [cell_data x_1 x_2 y_1 y_2];
dstrain = arrayDatastore(cell_data,’OutputType’,’same’);
%——————————————————————-
cell_data is of the form:
cell_data
cell_data =
10×4 cell array
{1×410 double} {1×410 double} {1×410 double} {[ 8]}
{1×410 double} {1×410 double} {1×410 double} {[10]}
{1×410 double} {1×410 double} {1×410 double} {[13]}
{1×410 double} {1×410 double} {1×410 double} {[20]}
{1×410 double} {1×410 double} {1×410 double} {[ 7]}
{1×410 double} {1×410 double} {1×410 double} {[ 8]}
{1×410 double} {1×410 double} {1×410 double} {[17]}
{1×410 double} {1×410 double} {1×410 double} {[ 6]}
{1×410 double} {1×410 double} {1×410 double} {[11]}
{1×410 double} {1×410 double} {1×410 double} {[ 8]}
If I were to use readall(dstrain) to read the datastore, I get the same format as cell_data:
fds = readall(dstrain)
fds =
10×4 cell array
{1×410 double} {1×410 double} {1×410 double} {[ 8]}
{1×410 double} {1×410 double} {1×410 double} {[10]}
{1×410 double} {1×410 double} {1×410 double} {[13]}
{1×410 double} {1×410 double} {1×410 double} {[20]}
{1×410 double} {1×410 double} {1×410 double} {[ 7]}
{1×410 double} {1×410 double} {1×410 double} {[ 8]}
{1×410 double} {1×410 double} {1×410 double} {[17]}
{1×410 double} {1×410 double} {1×410 double} {[ 6]}
{1×410 double} {1×410 double} {1×410 double} {[11]}
{1×410 double} {1×410 double} {1×410 double} {[ 8]}
Finally, if I use minibatchqueue to create a minibatch of datastore ‘dstrain’, I get:
mbq = minibatchqueue(dstrain)
mbq =
minibatchqueue with 4 outputs and properties:
Mini-batch creation:
MiniBatchSize: 10
PartialMiniBatch: ‘return’
MiniBatchFcn: ‘collate’
PreprocessingEnvironment: ‘serial’
Outputs:
OutputCast: {‘single’ ‘single’ ‘single’ ‘single’}
OutputAsDlarray: [1 1 1 1]
MiniBatchFormat: {” ” ” ”}
OutputEnvironment: {‘auto’ ‘auto’ ‘auto’ ‘auto’}
As you can see, there are four outputs for the minibatch, which appears to contradict the original error message that there are only two minibatchqueue outputs
Also to confirm, i double checked the transformer input output structure:
net
net =
dlnetwork with properties:
Layers: [64×1 nnet.cnn.layer.Layer]
Connections: [1714×2 table]
Learnables: [110×3 table]
State: [0×3 table]
InputNames: {‘in_enc’ ‘in_dec’}
OutputNames: {‘decoder_out’ ‘fc_13’}
Initialized: 1
View summary with summary.
which shows two inputs and two outputs.
Could someone point me to the mistake I’m making here (likely with the datastore format) – it seems that during batching, the model is only choosing two of the cell columns from cell_data/dstrain for the input and output, rather than all four and its not clear why…thanks in advance for your help!
CG The full error message reads "Error using trainnet (line 46)
The number of mini-batch queue outputs (2) must match the number of network inputs plus
the number of network outputs (4)."
I’m using an arrayDatastore to pass the predictors (x2) and the targets(x2) to the transformer model. Both predictors have 410 features, one of the targets has 410 features and the other target is a scalar function.
Code to generate the dummy predictor and target data is pasted below:
%——————————————————————–
% data generation for encoder
numObs = 10;
seqLen = vocabSize;
x_enc = randi([1,10],[seqLen,numObs]);
y_enc = zeros(numObs,1);
for i = 1:numObs
idx = x_enc(1:2,i);
y_enc(i,:) = sum(x_enc(idx,i));
end
x_enc = num2cell(x_enc’,2);
y_enc = num2cell(y_enc)’;
x_1 = x_enc;
y_2 = y_enc’;
% data generation for decoder
x_series = randi([1,10],[seqLen,numObs]);
y_series = sin(rand([seqLen,numObs]));
x_dec = x_series(:,1:end)’;
y_dec = y_series(:,1:end)’;
x_dec = num2cell(x_dec,2); x_2 = x_dec;
y_dec = num2cell(y_dec,2); y_1 = y_dec;
cell_data = {}; cell_data = [cell_data x_1 x_2 y_1 y_2];
dstrain = arrayDatastore(cell_data,’OutputType’,’same’);
%——————————————————————-
cell_data is of the form:
cell_data
cell_data =
10×4 cell array
{1×410 double} {1×410 double} {1×410 double} {[ 8]}
{1×410 double} {1×410 double} {1×410 double} {[10]}
{1×410 double} {1×410 double} {1×410 double} {[13]}
{1×410 double} {1×410 double} {1×410 double} {[20]}
{1×410 double} {1×410 double} {1×410 double} {[ 7]}
{1×410 double} {1×410 double} {1×410 double} {[ 8]}
{1×410 double} {1×410 double} {1×410 double} {[17]}
{1×410 double} {1×410 double} {1×410 double} {[ 6]}
{1×410 double} {1×410 double} {1×410 double} {[11]}
{1×410 double} {1×410 double} {1×410 double} {[ 8]}
If I were to use readall(dstrain) to read the datastore, I get the same format as cell_data:
fds = readall(dstrain)
fds =
10×4 cell array
{1×410 double} {1×410 double} {1×410 double} {[ 8]}
{1×410 double} {1×410 double} {1×410 double} {[10]}
{1×410 double} {1×410 double} {1×410 double} {[13]}
{1×410 double} {1×410 double} {1×410 double} {[20]}
{1×410 double} {1×410 double} {1×410 double} {[ 7]}
{1×410 double} {1×410 double} {1×410 double} {[ 8]}
{1×410 double} {1×410 double} {1×410 double} {[17]}
{1×410 double} {1×410 double} {1×410 double} {[ 6]}
{1×410 double} {1×410 double} {1×410 double} {[11]}
{1×410 double} {1×410 double} {1×410 double} {[ 8]}
Finally, if I use minibatchqueue to create a minibatch of datastore ‘dstrain’, I get:
mbq = minibatchqueue(dstrain)
mbq =
minibatchqueue with 4 outputs and properties:
Mini-batch creation:
MiniBatchSize: 10
PartialMiniBatch: ‘return’
MiniBatchFcn: ‘collate’
PreprocessingEnvironment: ‘serial’
Outputs:
OutputCast: {‘single’ ‘single’ ‘single’ ‘single’}
OutputAsDlarray: [1 1 1 1]
MiniBatchFormat: {” ” ” ”}
OutputEnvironment: {‘auto’ ‘auto’ ‘auto’ ‘auto’}
As you can see, there are four outputs for the minibatch, which appears to contradict the original error message that there are only two minibatchqueue outputs
Also to confirm, i double checked the transformer input output structure:
net
net =
dlnetwork with properties:
Layers: [64×1 nnet.cnn.layer.Layer]
Connections: [1714×2 table]
Learnables: [110×3 table]
State: [0×3 table]
InputNames: {‘in_enc’ ‘in_dec’}
OutputNames: {‘decoder_out’ ‘fc_13’}
Initialized: 1
View summary with summary.
which shows two inputs and two outputs.
Could someone point me to the mistake I’m making here (likely with the datastore format) – it seems that during batching, the model is only choosing two of the cell columns from cell_data/dstrain for the input and output, rather than all four and its not clear why…thanks in advance for your help!
CG deep learning, minibatch, datastore MATLAB Answers — New Questions
License manager causing more errors. So just making it test
Test to runTest to run Test to run cocktail party problem, blind source separation, independent components analysis, bss, ica, test MATLAB Answers — New Questions
Can I ‘initialize’ a handle object in such a way that isvalid(object) would return false?
I’m trying to initialize a variable (MyHandle) that I want to be a handle pointing to some object but which can’t currently be assigned to said object. I have code that needs to behave differently depending on if MyHandle is assigned or not yet and I haven’t found a good way to test if MyHandle has been assigned to a valid object or not.
The function ‘isvalid’ seems like the right choice to test this, however, isvalid throws the error "Incorrect number or types of inputs or outputs for function isvalid." when run on MyHandle in its unassigned state. I’ve tried different ways to initialize it like "handle([])" and "[]", but they all return that same error.
I’ve found some bandaid solutions like initializing MyHandle to an instance of some arbitrary handle subclass and then deleting that initialized object, or assigning MyHandle to be a value of type double and then using "isnumeric" as my test function instead of "isvalid," but I was wondering if there is a more "correct" way to do it for the sake of best practices.
Below is a sample class that recreates the behavior described above. To restate my question in terms of the class below: Is there an initialization for MyHandle I can use in the properties block that will allow IsHandleAssigned to return false before the first time AssignHandle is run with a valid handle and return true afterwards? OR is there a different function besides isvalid that I should be using in IsHandleAssigned to achieve that behavior?
classdef ExampleClass < handle
properties
MyHandle %Will be a handle pointing to an object of an arbitrary class
% MyHandle = handle([]) < This initialization returns an error
% MyHandle = [] < This initialization returns an error
% MyHandle = 0 < This works if I replace ‘isvalid’ with ‘isnumeric’
% but that seems like poor practice to do since it obfuscates the
% purpose of MyHandle
end
methods
function obj = AssignHandle(obj,handleIn)
%This method assigns the handle of whatever class it happens to
%be to my property.
obj.MyHandle = handleIn;
end
function HandleIsAssigned = IsHandleAssigned(obj)
%This method tests whether or not my handle was assigned. Is
%there a better function than isvalid to use?
HandleIsAssigned = isvalid(obj.MyHandle);
end
end
endI’m trying to initialize a variable (MyHandle) that I want to be a handle pointing to some object but which can’t currently be assigned to said object. I have code that needs to behave differently depending on if MyHandle is assigned or not yet and I haven’t found a good way to test if MyHandle has been assigned to a valid object or not.
The function ‘isvalid’ seems like the right choice to test this, however, isvalid throws the error "Incorrect number or types of inputs or outputs for function isvalid." when run on MyHandle in its unassigned state. I’ve tried different ways to initialize it like "handle([])" and "[]", but they all return that same error.
I’ve found some bandaid solutions like initializing MyHandle to an instance of some arbitrary handle subclass and then deleting that initialized object, or assigning MyHandle to be a value of type double and then using "isnumeric" as my test function instead of "isvalid," but I was wondering if there is a more "correct" way to do it for the sake of best practices.
Below is a sample class that recreates the behavior described above. To restate my question in terms of the class below: Is there an initialization for MyHandle I can use in the properties block that will allow IsHandleAssigned to return false before the first time AssignHandle is run with a valid handle and return true afterwards? OR is there a different function besides isvalid that I should be using in IsHandleAssigned to achieve that behavior?
classdef ExampleClass < handle
properties
MyHandle %Will be a handle pointing to an object of an arbitrary class
% MyHandle = handle([]) < This initialization returns an error
% MyHandle = [] < This initialization returns an error
% MyHandle = 0 < This works if I replace ‘isvalid’ with ‘isnumeric’
% but that seems like poor practice to do since it obfuscates the
% purpose of MyHandle
end
methods
function obj = AssignHandle(obj,handleIn)
%This method assigns the handle of whatever class it happens to
%be to my property.
obj.MyHandle = handleIn;
end
function HandleIsAssigned = IsHandleAssigned(obj)
%This method tests whether or not my handle was assigned. Is
%there a better function than isvalid to use?
HandleIsAssigned = isvalid(obj.MyHandle);
end
end
end I’m trying to initialize a variable (MyHandle) that I want to be a handle pointing to some object but which can’t currently be assigned to said object. I have code that needs to behave differently depending on if MyHandle is assigned or not yet and I haven’t found a good way to test if MyHandle has been assigned to a valid object or not.
The function ‘isvalid’ seems like the right choice to test this, however, isvalid throws the error "Incorrect number or types of inputs or outputs for function isvalid." when run on MyHandle in its unassigned state. I’ve tried different ways to initialize it like "handle([])" and "[]", but they all return that same error.
I’ve found some bandaid solutions like initializing MyHandle to an instance of some arbitrary handle subclass and then deleting that initialized object, or assigning MyHandle to be a value of type double and then using "isnumeric" as my test function instead of "isvalid," but I was wondering if there is a more "correct" way to do it for the sake of best practices.
Below is a sample class that recreates the behavior described above. To restate my question in terms of the class below: Is there an initialization for MyHandle I can use in the properties block that will allow IsHandleAssigned to return false before the first time AssignHandle is run with a valid handle and return true afterwards? OR is there a different function besides isvalid that I should be using in IsHandleAssigned to achieve that behavior?
classdef ExampleClass < handle
properties
MyHandle %Will be a handle pointing to an object of an arbitrary class
% MyHandle = handle([]) < This initialization returns an error
% MyHandle = [] < This initialization returns an error
% MyHandle = 0 < This works if I replace ‘isvalid’ with ‘isnumeric’
% but that seems like poor practice to do since it obfuscates the
% purpose of MyHandle
end
methods
function obj = AssignHandle(obj,handleIn)
%This method assigns the handle of whatever class it happens to
%be to my property.
obj.MyHandle = handleIn;
end
function HandleIsAssigned = IsHandleAssigned(obj)
%This method tests whether or not my handle was assigned. Is
%there a better function than isvalid to use?
HandleIsAssigned = isvalid(obj.MyHandle);
end
end
end handles MATLAB Answers — New Questions
getting group delay by differentiating phase of reflectance
Hi all
I am trying to calculate and draw the group delay of contradirectional bragg grating.
I already calculated the reflectance and got its phase as shown in the figure.
when I differentiate the phase i got unlogical spikes like that figure
while the correct plot is shown in Yariv book as the following figure (trace denoted by taw)
to differentiate i tried two functions diff and gradient and both gave me the same spikes (which is wrong). These are the lines i used in matlab:
Reflection=S11;
R=abs(Reflection).^2;
R_phase2=unwrap(angle(Reflection));
phase_lambda=lambda*1e9;
dphasedlambda1 =-phase_lambda.^2./(2*pi*c).*( gradient(R_phase2) ./ gradient(phase_lambda));
dphasedlambda2 =-phase_lambda(1:end-1).^2./(2*pi*c).*( diff(R_phase2) ./ diff(phase_lambda));
Any help with that problemHi all
I am trying to calculate and draw the group delay of contradirectional bragg grating.
I already calculated the reflectance and got its phase as shown in the figure.
when I differentiate the phase i got unlogical spikes like that figure
while the correct plot is shown in Yariv book as the following figure (trace denoted by taw)
to differentiate i tried two functions diff and gradient and both gave me the same spikes (which is wrong). These are the lines i used in matlab:
Reflection=S11;
R=abs(Reflection).^2;
R_phase2=unwrap(angle(Reflection));
phase_lambda=lambda*1e9;
dphasedlambda1 =-phase_lambda.^2./(2*pi*c).*( gradient(R_phase2) ./ gradient(phase_lambda));
dphasedlambda2 =-phase_lambda(1:end-1).^2./(2*pi*c).*( diff(R_phase2) ./ diff(phase_lambda));
Any help with that problem Hi all
I am trying to calculate and draw the group delay of contradirectional bragg grating.
I already calculated the reflectance and got its phase as shown in the figure.
when I differentiate the phase i got unlogical spikes like that figure
while the correct plot is shown in Yariv book as the following figure (trace denoted by taw)
to differentiate i tried two functions diff and gradient and both gave me the same spikes (which is wrong). These are the lines i used in matlab:
Reflection=S11;
R=abs(Reflection).^2;
R_phase2=unwrap(angle(Reflection));
phase_lambda=lambda*1e9;
dphasedlambda1 =-phase_lambda.^2./(2*pi*c).*( gradient(R_phase2) ./ gradient(phase_lambda));
dphasedlambda2 =-phase_lambda(1:end-1).^2./(2*pi*c).*( diff(R_phase2) ./ diff(phase_lambda));
Any help with that problem group delay, bragg, phase differentiation MATLAB Answers — New Questions