Category: Matlab
Category Archives: Matlab
How to access the system clipboard in MATLAB Web App Server
I am creating an app in MATLAB Web App Server 2024a. Accessing the system’s clipboard using the clipboard function is not supported, as described in the unsupported functionality page. I am looking for an alternative so that users can paste the contents of their clipboard into a UITable.
Interestingly, despite the lack of support for the clipboard function, users are still able to paste text from their clipboard using the key combination to paste if they double click a cell in the table first so that there’s a flashing cursor. This leads me to believe that Web App Server is able to access the system clipboard, although I can’t seem to figure out how to do so (ie. if there’s a different function to call). Is there a way for me to access the user’s clipboard in Web App Server without the clipboard function? As it stands, users can only paste if they’ve double-clicked a cell in the table. A single click won’t do, and I’d like to add functionality to enable that.
Any insights are appreciated. Thank you!I am creating an app in MATLAB Web App Server 2024a. Accessing the system’s clipboard using the clipboard function is not supported, as described in the unsupported functionality page. I am looking for an alternative so that users can paste the contents of their clipboard into a UITable.
Interestingly, despite the lack of support for the clipboard function, users are still able to paste text from their clipboard using the key combination to paste if they double click a cell in the table first so that there’s a flashing cursor. This leads me to believe that Web App Server is able to access the system clipboard, although I can’t seem to figure out how to do so (ie. if there’s a different function to call). Is there a way for me to access the user’s clipboard in Web App Server without the clipboard function? As it stands, users can only paste if they’ve double-clicked a cell in the table. A single click won’t do, and I’d like to add functionality to enable that.
Any insights are appreciated. Thank you! I am creating an app in MATLAB Web App Server 2024a. Accessing the system’s clipboard using the clipboard function is not supported, as described in the unsupported functionality page. I am looking for an alternative so that users can paste the contents of their clipboard into a UITable.
Interestingly, despite the lack of support for the clipboard function, users are still able to paste text from their clipboard using the key combination to paste if they double click a cell in the table first so that there’s a flashing cursor. This leads me to believe that Web App Server is able to access the system clipboard, although I can’t seem to figure out how to do so (ie. if there’s a different function to call). Is there a way for me to access the user’s clipboard in Web App Server without the clipboard function? As it stands, users can only paste if they’ve double-clicked a cell in the table. A single click won’t do, and I’d like to add functionality to enable that.
Any insights are appreciated. Thank you! matlab, appdesigner, web app server, clipboard, uitable MATLAB Answers — New Questions
exponential increase in wave form in three phase grid connected svpwm
for the three phase grid connected system for the svpwm i have used the angle from pll, sector selection is also obtained using pll,vdc of 400v and Ts=1/10000. i have used current controller for obtaining vref. i’m experiencing exponentially increasing waveform in vref. what should i do to settle it downfor the three phase grid connected system for the svpwm i have used the angle from pll, sector selection is also obtained using pll,vdc of 400v and Ts=1/10000. i have used current controller for obtaining vref. i’m experiencing exponentially increasing waveform in vref. what should i do to settle it down for the three phase grid connected system for the svpwm i have used the angle from pll, sector selection is also obtained using pll,vdc of 400v and Ts=1/10000. i have used current controller for obtaining vref. i’m experiencing exponentially increasing waveform in vref. what should i do to settle it down exponential increase in vref in svpwm MATLAB Answers — New Questions
PSO algorithm value problem
Hi
I have a pso code, but i have a little problem. Here is a code
clc;
clear;
close all;
%% Problem Definition
CostFunction = @(x) Sphere(x); % Cost Function
nVar = 5; % Number of Unknown (Deceision) Variables
VarSize = [1 nVar]; % Matrix Size of Decision Variables
VarMin = -10; % Lower bound of Decesion Variable
VarMax = 10; % Upper bound of Decesion Variable
%% Parameters of PSO
MaxIt = 100; % Maximum Number of Iterations
nPop = 50; % Population Size (Swarm Size)
wdamp = 0.99; % Damping Ratio of Inertia Coefficient
w = 1; % Inertia Coefficient
c1 = 2; % Personal Acceleration Coefficient
c2 = 2; % Social Acceleration Coefficient
%% Initialization
% The Particle Template
empty_particle.Position = [];
empty_particle.Velocity = [];
empty_particle.Cost = [];
empty_particle.Best.Position = [];
empty_particle.Best.Cost = [];
% Create Population Array
particle = repmat(empty_particle, nPop, 1);
% Initialize Global Best
GlobalBest.Cost = inf;
% Initialize Population Members
for i=1:nPop
% Generate Random Solution
particle(i).Position = unifrnd(VarMin, VarMax, VarSize);
% Initialize Velocity
particle(i).Velocity = zeros(VarSize);
% Evaluation
particle(i).Cost = CostFunction(particle(i).Position);
% Update the Personal Best
particle(i).Best.Position = particle(i).Position;
particle(i).Best.Cost = particle(i).Cost;
% Update Global Best
if particle(i).Best.Cost < GlobalBest.Cost
GlobalBest = particle(i).Best;
end
end
%
% Array to Hold Best Cost Value on Each Iteration
BestCosts = zeros(MaxIt, 1);
%% Main Loop of PSO
for it=1:MaxIt
for i=1:nPop
% Update Velocity
particle(i).Velocity = w*particle(i).Velocity …
+ c1*rand(VarSize).*(particle(i).Best.Position – particle(i).Position) …
+ c2*rand(VarSize).*(GlobalBest.Position – particle(i).Position);
% Update Position
particle(i).Postion = particle(i).Position + particle(i).Velocity;
% Evaluation
particle(i).Cost = CostFunction(particle(i).Position);
% Update Personal Best
if particle(i).Cost < particle(i).Best.Cost
particle(i).Best.Position = particle(i).Position;
particle(i).Best.Cost = particle(i).Cost;
% Update Global Best
if particle(i).Best.Cost < GlobalBest.Cost
GlobalBest = particle(i).Best;
end
end
end
% Store the Best Cost Value
BestCosts(it) = GlobalBest.Cost;
% Display Iteration Information
disp([‘Iteration ‘ num2str(it) ‘: Best Cost = ‘ num2str(BestCosts(it))]);
% Damping Interia Coefficient
w = w * wdamp;
end
figure;
plot(BestCosts, ‘LineWidth’, 2);
xlabel(‘Iteration’);
ylabel(‘Best Cost’);
grid on;
Value of BestCosts is alwyas the same, but shouldnt. I dont know how to fix it. Please help me.Hi
I have a pso code, but i have a little problem. Here is a code
clc;
clear;
close all;
%% Problem Definition
CostFunction = @(x) Sphere(x); % Cost Function
nVar = 5; % Number of Unknown (Deceision) Variables
VarSize = [1 nVar]; % Matrix Size of Decision Variables
VarMin = -10; % Lower bound of Decesion Variable
VarMax = 10; % Upper bound of Decesion Variable
%% Parameters of PSO
MaxIt = 100; % Maximum Number of Iterations
nPop = 50; % Population Size (Swarm Size)
wdamp = 0.99; % Damping Ratio of Inertia Coefficient
w = 1; % Inertia Coefficient
c1 = 2; % Personal Acceleration Coefficient
c2 = 2; % Social Acceleration Coefficient
%% Initialization
% The Particle Template
empty_particle.Position = [];
empty_particle.Velocity = [];
empty_particle.Cost = [];
empty_particle.Best.Position = [];
empty_particle.Best.Cost = [];
% Create Population Array
particle = repmat(empty_particle, nPop, 1);
% Initialize Global Best
GlobalBest.Cost = inf;
% Initialize Population Members
for i=1:nPop
% Generate Random Solution
particle(i).Position = unifrnd(VarMin, VarMax, VarSize);
% Initialize Velocity
particle(i).Velocity = zeros(VarSize);
% Evaluation
particle(i).Cost = CostFunction(particle(i).Position);
% Update the Personal Best
particle(i).Best.Position = particle(i).Position;
particle(i).Best.Cost = particle(i).Cost;
% Update Global Best
if particle(i).Best.Cost < GlobalBest.Cost
GlobalBest = particle(i).Best;
end
end
%
% Array to Hold Best Cost Value on Each Iteration
BestCosts = zeros(MaxIt, 1);
%% Main Loop of PSO
for it=1:MaxIt
for i=1:nPop
% Update Velocity
particle(i).Velocity = w*particle(i).Velocity …
+ c1*rand(VarSize).*(particle(i).Best.Position – particle(i).Position) …
+ c2*rand(VarSize).*(GlobalBest.Position – particle(i).Position);
% Update Position
particle(i).Postion = particle(i).Position + particle(i).Velocity;
% Evaluation
particle(i).Cost = CostFunction(particle(i).Position);
% Update Personal Best
if particle(i).Cost < particle(i).Best.Cost
particle(i).Best.Position = particle(i).Position;
particle(i).Best.Cost = particle(i).Cost;
% Update Global Best
if particle(i).Best.Cost < GlobalBest.Cost
GlobalBest = particle(i).Best;
end
end
end
% Store the Best Cost Value
BestCosts(it) = GlobalBest.Cost;
% Display Iteration Information
disp([‘Iteration ‘ num2str(it) ‘: Best Cost = ‘ num2str(BestCosts(it))]);
% Damping Interia Coefficient
w = w * wdamp;
end
figure;
plot(BestCosts, ‘LineWidth’, 2);
xlabel(‘Iteration’);
ylabel(‘Best Cost’);
grid on;
Value of BestCosts is alwyas the same, but shouldnt. I dont know how to fix it. Please help me. Hi
I have a pso code, but i have a little problem. Here is a code
clc;
clear;
close all;
%% Problem Definition
CostFunction = @(x) Sphere(x); % Cost Function
nVar = 5; % Number of Unknown (Deceision) Variables
VarSize = [1 nVar]; % Matrix Size of Decision Variables
VarMin = -10; % Lower bound of Decesion Variable
VarMax = 10; % Upper bound of Decesion Variable
%% Parameters of PSO
MaxIt = 100; % Maximum Number of Iterations
nPop = 50; % Population Size (Swarm Size)
wdamp = 0.99; % Damping Ratio of Inertia Coefficient
w = 1; % Inertia Coefficient
c1 = 2; % Personal Acceleration Coefficient
c2 = 2; % Social Acceleration Coefficient
%% Initialization
% The Particle Template
empty_particle.Position = [];
empty_particle.Velocity = [];
empty_particle.Cost = [];
empty_particle.Best.Position = [];
empty_particle.Best.Cost = [];
% Create Population Array
particle = repmat(empty_particle, nPop, 1);
% Initialize Global Best
GlobalBest.Cost = inf;
% Initialize Population Members
for i=1:nPop
% Generate Random Solution
particle(i).Position = unifrnd(VarMin, VarMax, VarSize);
% Initialize Velocity
particle(i).Velocity = zeros(VarSize);
% Evaluation
particle(i).Cost = CostFunction(particle(i).Position);
% Update the Personal Best
particle(i).Best.Position = particle(i).Position;
particle(i).Best.Cost = particle(i).Cost;
% Update Global Best
if particle(i).Best.Cost < GlobalBest.Cost
GlobalBest = particle(i).Best;
end
end
%
% Array to Hold Best Cost Value on Each Iteration
BestCosts = zeros(MaxIt, 1);
%% Main Loop of PSO
for it=1:MaxIt
for i=1:nPop
% Update Velocity
particle(i).Velocity = w*particle(i).Velocity …
+ c1*rand(VarSize).*(particle(i).Best.Position – particle(i).Position) …
+ c2*rand(VarSize).*(GlobalBest.Position – particle(i).Position);
% Update Position
particle(i).Postion = particle(i).Position + particle(i).Velocity;
% Evaluation
particle(i).Cost = CostFunction(particle(i).Position);
% Update Personal Best
if particle(i).Cost < particle(i).Best.Cost
particle(i).Best.Position = particle(i).Position;
particle(i).Best.Cost = particle(i).Cost;
% Update Global Best
if particle(i).Best.Cost < GlobalBest.Cost
GlobalBest = particle(i).Best;
end
end
end
% Store the Best Cost Value
BestCosts(it) = GlobalBest.Cost;
% Display Iteration Information
disp([‘Iteration ‘ num2str(it) ‘: Best Cost = ‘ num2str(BestCosts(it))]);
% Damping Interia Coefficient
w = w * wdamp;
end
figure;
plot(BestCosts, ‘LineWidth’, 2);
xlabel(‘Iteration’);
ylabel(‘Best Cost’);
grid on;
Value of BestCosts is alwyas the same, but shouldnt. I dont know how to fix it. Please help me. pso algorithm MATLAB Answers — New Questions
get all rows from table by more than one categorical
Hi All,
I want to filter my table and get subtables for statistical calcs.
I use the commant:
D=table
D_sub=D(D.LogID== ‘2’,:);
To get all rows with the LogID 2. How can I expand this commant to get for example all data from LogID 2,3,4 and 5 with one commant?
Than you
MarkusHi All,
I want to filter my table and get subtables for statistical calcs.
I use the commant:
D=table
D_sub=D(D.LogID== ‘2’,:);
To get all rows with the LogID 2. How can I expand this commant to get for example all data from LogID 2,3,4 and 5 with one commant?
Than you
Markus Hi All,
I want to filter my table and get subtables for statistical calcs.
I use the commant:
D=table
D_sub=D(D.LogID== ‘2’,:);
To get all rows with the LogID 2. How can I expand this commant to get for example all data from LogID 2,3,4 and 5 with one commant?
Than you
Markus table, subtable, categorical, matlab MATLAB Answers — New Questions
callback in TreeNode Propertis
hi, i want to execute calback by click Node2 to execute other function
It’s possibile to do it?hi, i want to execute calback by click Node2 to execute other function
It’s possibile to do it? hi, i want to execute calback by click Node2 to execute other function
It’s possibile to do it? callback in treenode propertis MATLAB Answers — New Questions
Linear Regression, line of best fit
If I have data for vectors x = [ ] and y= [ ], how do I find and plot the linear regression/line of best fit? Once I have plotted the line of best fit, how do I record the slope of that line of best fit to some variable "a"?If I have data for vectors x = [ ] and y= [ ], how do I find and plot the linear regression/line of best fit? Once I have plotted the line of best fit, how do I record the slope of that line of best fit to some variable "a"? If I have data for vectors x = [ ] and y= [ ], how do I find and plot the linear regression/line of best fit? Once I have plotted the line of best fit, how do I record the slope of that line of best fit to some variable "a"? line of best fit MATLAB Answers — New Questions
Your variables are reaching 2GB limit,revert to save -v7.3 This will be slower but avoids matlab not saving the data.
When I was processing data with MATLAB on Ubuntu 20, I received the following message:
Your variables are reaching 2GB limit, revert to save -v7.3
This will be slower but avoids matlab not saving the data
I then changed the MAT file save format to 7.3 in the MATLAB preferences, but after restarting the software and the computer, I still encountered the same error when processing data. How should I resolve this?When I was processing data with MATLAB on Ubuntu 20, I received the following message:
Your variables are reaching 2GB limit, revert to save -v7.3
This will be slower but avoids matlab not saving the data
I then changed the MAT file save format to 7.3 in the MATLAB preferences, but after restarting the software and the computer, I still encountered the same error when processing data. How should I resolve this? When I was processing data with MATLAB on Ubuntu 20, I received the following message:
Your variables are reaching 2GB limit, revert to save -v7.3
This will be slower but avoids matlab not saving the data
I then changed the MAT file save format to 7.3 in the MATLAB preferences, but after restarting the software and the computer, I still encountered the same error when processing data. How should I resolve this? variables limit, ubuntu MATLAB Answers — New Questions
Changing colors of outlier markers, median and whiskers in a box and whisker plot
Hello,
So, currently I have the following script to generate a box and whisker plot:
x1 = randn(128, 1);
x2 = randn(100, 1);
X = [x1; x2];
colors = [0 0.4470 0.7410; 0.8500 0.3250 0.0980];
grp = [ones(size(x1)); 2.*ones(size(x2))];
h = boxplot(X, grp, …
‘Colors’,colors, …
‘Symbol’,’.’)
for j=1:size(h,2)
patch(get(h(5,j),’XData’),get(h(5,j),’YData’),get(h(5,j),’Color’),’FaceAlpha’,.7);
end
The result I get is this one:
What I would like to do is to make the whisker line, the median line and the outline markers all black. The end result would be something like this:
Thanks!Hello,
So, currently I have the following script to generate a box and whisker plot:
x1 = randn(128, 1);
x2 = randn(100, 1);
X = [x1; x2];
colors = [0 0.4470 0.7410; 0.8500 0.3250 0.0980];
grp = [ones(size(x1)); 2.*ones(size(x2))];
h = boxplot(X, grp, …
‘Colors’,colors, …
‘Symbol’,’.’)
for j=1:size(h,2)
patch(get(h(5,j),’XData’),get(h(5,j),’YData’),get(h(5,j),’Color’),’FaceAlpha’,.7);
end
The result I get is this one:
What I would like to do is to make the whisker line, the median line and the outline markers all black. The end result would be something like this:
Thanks! Hello,
So, currently I have the following script to generate a box and whisker plot:
x1 = randn(128, 1);
x2 = randn(100, 1);
X = [x1; x2];
colors = [0 0.4470 0.7410; 0.8500 0.3250 0.0980];
grp = [ones(size(x1)); 2.*ones(size(x2))];
h = boxplot(X, grp, …
‘Colors’,colors, …
‘Symbol’,’.’)
for j=1:size(h,2)
patch(get(h(5,j),’XData’),get(h(5,j),’YData’),get(h(5,j),’Color’),’FaceAlpha’,.7);
end
The result I get is this one:
What I would like to do is to make the whisker line, the median line and the outline markers all black. The end result would be something like this:
Thanks! plotting, plot MATLAB Answers — New Questions
Run Python function from inside Simulink
Hello!
I have a simulink electric motor example that is being controlled via PWM.
I want the controller that spits out the PWM to be a Python function ( a NN controller I have written in Python INPUT: motor rpm OUT: PWM signal) — and it returns in real time floating point numbers. e.g. 2,504; 2,103 etc.
I want that to be the input for the PWM block in the Simulink model. And the output of the electric motor (rpm) to be the input for the Python function (I have a special measurement input for that function).
Has anybody had any succes with linking .py files and Simulink ?
__________________________________________________________________________________________________________
And to run the python files, do I need to containerize them or to do something special ? Because there are 5 files in the whole project which I will need. I cannot run the function alone.
Thanks a lot!Hello!
I have a simulink electric motor example that is being controlled via PWM.
I want the controller that spits out the PWM to be a Python function ( a NN controller I have written in Python INPUT: motor rpm OUT: PWM signal) — and it returns in real time floating point numbers. e.g. 2,504; 2,103 etc.
I want that to be the input for the PWM block in the Simulink model. And the output of the electric motor (rpm) to be the input for the Python function (I have a special measurement input for that function).
Has anybody had any succes with linking .py files and Simulink ?
__________________________________________________________________________________________________________
And to run the python files, do I need to containerize them or to do something special ? Because there are 5 files in the whole project which I will need. I cannot run the function alone.
Thanks a lot! Hello!
I have a simulink electric motor example that is being controlled via PWM.
I want the controller that spits out the PWM to be a Python function ( a NN controller I have written in Python INPUT: motor rpm OUT: PWM signal) — and it returns in real time floating point numbers. e.g. 2,504; 2,103 etc.
I want that to be the input for the PWM block in the Simulink model. And the output of the electric motor (rpm) to be the input for the Python function (I have a special measurement input for that function).
Has anybody had any succes with linking .py files and Simulink ?
__________________________________________________________________________________________________________
And to run the python files, do I need to containerize them or to do something special ? Because there are 5 files in the whole project which I will need. I cannot run the function alone.
Thanks a lot! python, simulink, electric_motor_control, embedded matlab function MATLAB Answers — New Questions
assignin function does not work from export function
Hello.
We’re using the export function to run an *.mlx file and then export it to a pdf.
I don’t seem to be able to interact with the OS filesystem or store data in the base workspace when the *.mlx is executed using the export function
export("Analyse_Template",filename,PageSize="A4",Run=true,FigureResolution=800,HideCode=true);
% using assignin does not work
assignin(‘base’,’OutPutTable’,OutPutTable)
% using writetable does not work
writetable(inputTable, FName,"WriteMode","append");
Executing the *.mlx file itself produces the desired results.
Why can I not work outside of the scope of the export function?
Many thanks in advance.Hello.
We’re using the export function to run an *.mlx file and then export it to a pdf.
I don’t seem to be able to interact with the OS filesystem or store data in the base workspace when the *.mlx is executed using the export function
export("Analyse_Template",filename,PageSize="A4",Run=true,FigureResolution=800,HideCode=true);
% using assignin does not work
assignin(‘base’,’OutPutTable’,OutPutTable)
% using writetable does not work
writetable(inputTable, FName,"WriteMode","append");
Executing the *.mlx file itself produces the desired results.
Why can I not work outside of the scope of the export function?
Many thanks in advance. Hello.
We’re using the export function to run an *.mlx file and then export it to a pdf.
I don’t seem to be able to interact with the OS filesystem or store data in the base workspace when the *.mlx is executed using the export function
export("Analyse_Template",filename,PageSize="A4",Run=true,FigureResolution=800,HideCode=true);
% using assignin does not work
assignin(‘base’,’OutPutTable’,OutPutTable)
% using writetable does not work
writetable(inputTable, FName,"WriteMode","append");
Executing the *.mlx file itself produces the desired results.
Why can I not work outside of the scope of the export function?
Many thanks in advance. export, live script, assignin MATLAB Answers — New Questions
Error forming mini-batch for network input “input”. Data interpreted with format “SSCB”. To specify a different format, use the InputDataFormats option.
I am working on a binary classification of images.the code i am using is as follows.
In short, the ‘data’ file contains an image as 320*100*2 in its cell. 320 is width, 100 is height and 2 is channel (gmti is a name for channel 1, ref is a name for channel 2).
I have 290 images in total so ‘data’ is a 290*1 cell. 290 as batch, 320*100 as spece, 2 as channel. (SSCB)
For labels, I simply labeled then as double 0 or 1, and used num2str and converted it into categorical.
the error message is as such.
trainnet:
Error forming mini-batch for network input "input". Data interpreted with format "SSCB". To specify a different format, use the InputDataFormats option.
net_trained = trainnet(data,labels_cat, net,’crossentropy’,options);
Cause:
Cell array input supports sequence data only.
I tried changing input layer as sequence and making data format as 320*100*2*290 double. Did not work.
Exactly what is the proper data format should i use?
———————————————————————————————————-
clear
close all
for i = 1 : size(gmti, 1)
data{i,1}(:,:,1) = [gmti{i}];
data{i,1}(:,:,2) = [ref{i}];
end
mm = 1;
for i = size(gmti, 1) + 1 : size(gmti, 1) + size(gmti2, 1)
data{i,1}(:,:,1) = [gmti2{mm}];
data{i,1}(:,:,2) = [ref2{mm}];
mm = mm+1;
end
data2 = zeros(320, 100, 2, 290);
for i = 1 : size(data,1)
data2(:,:,:, i)=data{i, 1};
end
labels = [label; label2];
labels_cat = {};
for i =1 : size(labels, 1)
labels_cat{i, 1} = num2str(labels(i, 1));
end
labels_cat = categorical(labels_cat);
%%
% imds = imageDatastore(data, ‘Labels’,labels_cat);
%%
imageSize = [320 100 2];
numClasses = 2;
stackDepth = [3 4 23 3];
numFilters = [64 128 256 512];
net = resnetNetwork(imageSize,numClasses, …
StackDepth=stackDepth, …
NumFilters=numFilters);
% analyzeNetwork(net)
% net = replaceLayer(net, ‘input’, sequenceInputLayer(imageSize));
options = trainingOptions("sgdm", …
InitialLearnRate=0.01, …
MaxEpochs=100, …
Shuffle="every-epoch", …
Plots="training-progress", …
Verbose=false);
% InputDataFormats = "SSCB", …
%%
%%
net_trained = trainnet(data,labels_cat, net,’crossentropy’,options);I am working on a binary classification of images.the code i am using is as follows.
In short, the ‘data’ file contains an image as 320*100*2 in its cell. 320 is width, 100 is height and 2 is channel (gmti is a name for channel 1, ref is a name for channel 2).
I have 290 images in total so ‘data’ is a 290*1 cell. 290 as batch, 320*100 as spece, 2 as channel. (SSCB)
For labels, I simply labeled then as double 0 or 1, and used num2str and converted it into categorical.
the error message is as such.
trainnet:
Error forming mini-batch for network input "input". Data interpreted with format "SSCB". To specify a different format, use the InputDataFormats option.
net_trained = trainnet(data,labels_cat, net,’crossentropy’,options);
Cause:
Cell array input supports sequence data only.
I tried changing input layer as sequence and making data format as 320*100*2*290 double. Did not work.
Exactly what is the proper data format should i use?
———————————————————————————————————-
clear
close all
for i = 1 : size(gmti, 1)
data{i,1}(:,:,1) = [gmti{i}];
data{i,1}(:,:,2) = [ref{i}];
end
mm = 1;
for i = size(gmti, 1) + 1 : size(gmti, 1) + size(gmti2, 1)
data{i,1}(:,:,1) = [gmti2{mm}];
data{i,1}(:,:,2) = [ref2{mm}];
mm = mm+1;
end
data2 = zeros(320, 100, 2, 290);
for i = 1 : size(data,1)
data2(:,:,:, i)=data{i, 1};
end
labels = [label; label2];
labels_cat = {};
for i =1 : size(labels, 1)
labels_cat{i, 1} = num2str(labels(i, 1));
end
labels_cat = categorical(labels_cat);
%%
% imds = imageDatastore(data, ‘Labels’,labels_cat);
%%
imageSize = [320 100 2];
numClasses = 2;
stackDepth = [3 4 23 3];
numFilters = [64 128 256 512];
net = resnetNetwork(imageSize,numClasses, …
StackDepth=stackDepth, …
NumFilters=numFilters);
% analyzeNetwork(net)
% net = replaceLayer(net, ‘input’, sequenceInputLayer(imageSize));
options = trainingOptions("sgdm", …
InitialLearnRate=0.01, …
MaxEpochs=100, …
Shuffle="every-epoch", …
Plots="training-progress", …
Verbose=false);
% InputDataFormats = "SSCB", …
%%
%%
net_trained = trainnet(data,labels_cat, net,’crossentropy’,options); I am working on a binary classification of images.the code i am using is as follows.
In short, the ‘data’ file contains an image as 320*100*2 in its cell. 320 is width, 100 is height and 2 is channel (gmti is a name for channel 1, ref is a name for channel 2).
I have 290 images in total so ‘data’ is a 290*1 cell. 290 as batch, 320*100 as spece, 2 as channel. (SSCB)
For labels, I simply labeled then as double 0 or 1, and used num2str and converted it into categorical.
the error message is as such.
trainnet:
Error forming mini-batch for network input "input". Data interpreted with format "SSCB". To specify a different format, use the InputDataFormats option.
net_trained = trainnet(data,labels_cat, net,’crossentropy’,options);
Cause:
Cell array input supports sequence data only.
I tried changing input layer as sequence and making data format as 320*100*2*290 double. Did not work.
Exactly what is the proper data format should i use?
———————————————————————————————————-
clear
close all
for i = 1 : size(gmti, 1)
data{i,1}(:,:,1) = [gmti{i}];
data{i,1}(:,:,2) = [ref{i}];
end
mm = 1;
for i = size(gmti, 1) + 1 : size(gmti, 1) + size(gmti2, 1)
data{i,1}(:,:,1) = [gmti2{mm}];
data{i,1}(:,:,2) = [ref2{mm}];
mm = mm+1;
end
data2 = zeros(320, 100, 2, 290);
for i = 1 : size(data,1)
data2(:,:,:, i)=data{i, 1};
end
labels = [label; label2];
labels_cat = {};
for i =1 : size(labels, 1)
labels_cat{i, 1} = num2str(labels(i, 1));
end
labels_cat = categorical(labels_cat);
%%
% imds = imageDatastore(data, ‘Labels’,labels_cat);
%%
imageSize = [320 100 2];
numClasses = 2;
stackDepth = [3 4 23 3];
numFilters = [64 128 256 512];
net = resnetNetwork(imageSize,numClasses, …
StackDepth=stackDepth, …
NumFilters=numFilters);
% analyzeNetwork(net)
% net = replaceLayer(net, ‘input’, sequenceInputLayer(imageSize));
options = trainingOptions("sgdm", …
InitialLearnRate=0.01, …
MaxEpochs=100, …
Shuffle="every-epoch", …
Plots="training-progress", …
Verbose=false);
% InputDataFormats = "SSCB", …
%%
%%
net_trained = trainnet(data,labels_cat, net,’crossentropy’,options); deep learning, resnet, input, data, format, input format MATLAB Answers — New Questions
How to open and modify .dat file
Hello Everyone,
Anyone can help me.
I have one .dat file as attached. According to the manual, the description of my file is 364 × 364 × 110, integer, 8-bit.
Anyone can help how to open my file.
Then how to modify some infi like the geometry.Hello Everyone,
Anyone can help me.
I have one .dat file as attached. According to the manual, the description of my file is 364 × 364 × 110, integer, 8-bit.
Anyone can help how to open my file.
Then how to modify some infi like the geometry. Hello Everyone,
Anyone can help me.
I have one .dat file as attached. According to the manual, the description of my file is 364 × 364 × 110, integer, 8-bit.
Anyone can help how to open my file.
Then how to modify some infi like the geometry. file, image, image analysis, image acquisition, image segmentation, digital image processing, image processing MATLAB Answers — New Questions
Why can I not download “Library for interfacing with IIO devices’ using matlab 2018a
Why can I not download "Library for interfacing Library for interfacing Library for interfacing with IIO devices’ using matlab 2018aWhy can I not download "Library for interfacing Library for interfacing Library for interfacing with IIO devices’ using matlab 2018a Why can I not download "Library for interfacing Library for interfacing Library for interfacing with IIO devices’ using matlab 2018a library for interfacing MATLAB Answers — New Questions
Trying to read digital input with F28379D LaunchPad
Hello everyone.
I’m using the F28379D LaunchPad in Simulink and I want to read some Digital Inputs to read the pulses of a quadrature encoder and make a pulse count. I know that the board has built in pins to read quadrature encoder but I want to try reading it by the digital input pins. The problem is that I put a Scope and a Display and the value doesn’t change. I already checked that the encoder works, I tried input a square signal, even using a push button with pull-down resistor and the value doesn’t change at all. Here is the piece of code of what I am doing.
Hope someone can help me. Thanks in advance.Hello everyone.
I’m using the F28379D LaunchPad in Simulink and I want to read some Digital Inputs to read the pulses of a quadrature encoder and make a pulse count. I know that the board has built in pins to read quadrature encoder but I want to try reading it by the digital input pins. The problem is that I put a Scope and a Display and the value doesn’t change. I already checked that the encoder works, I tried input a square signal, even using a push button with pull-down resistor and the value doesn’t change at all. Here is the piece of code of what I am doing.
Hope someone can help me. Thanks in advance. Hello everyone.
I’m using the F28379D LaunchPad in Simulink and I want to read some Digital Inputs to read the pulses of a quadrature encoder and make a pulse count. I know that the board has built in pins to read quadrature encoder but I want to try reading it by the digital input pins. The problem is that I put a Scope and a Display and the value doesn’t change. I already checked that the encoder works, I tried input a square signal, even using a push button with pull-down resistor and the value doesn’t change at all. Here is the piece of code of what I am doing.
Hope someone can help me. Thanks in advance. simulink MATLAB Answers — New Questions
Errors calling python scripts in virtual environment on raspberry pi (MCC Daqhat Library) – with a possible answer
I’m posting this mostly as help to someone else trying to develop a system using MCC’s DAQHATS. There are very little resources regarding using Daqhats from MCC from Matlab (unsupported) or MCC.
The installation of the DAQHAT python library requires that it be installed into a virtual environment. That was causing us issues expecially when we need to run 2 scripts back to back. It would close the virtual environment after the first script.
The following is the question we submitted to Matlab’s help team:
Description: We are using MCC Daqhats. First, I know this is not a supported hardware for Matlab. We are not asking for support for that. However, in the process of installing the python libraries for the Daqhats, we are forced to install them into a virtual environment. We believe this is causing us problems. We need to run multiple scripts in a row. We think that after the first call it is exiting the virtual environment but we are not certain of that.
The matlab file calling the python script is attached. The python script we are calling is attached. We have tested the python script on the PI and it runs properly both from python and the command line.
here is our Matlab error:
Error using datacollection
Error executing command "python3 /home/aset/daqhats/examples/python/mcc172/bert2.py". Details:
STDERR: Traceback (most recent call last):
File "/home/aset/daqhats/examples/python/mcc172/bert2.py", line 3, in <module>
from daqhats import mcc172, OptionFlags, SourceType, HatIDs, HatError
ModuleNotFoundError: No module named ‘daqhats’
Our Solution was as follows: (However others may have a better solution)
We have been able to get it to work by explicitly calling the virtual environment in the system command. This was found using a resource other than a Matlab site.
system(rpi, ‘/home/aset/environments/bin/python3 /home/aset/daqhats/examples/python/mcc172/bert2.py’)I’m posting this mostly as help to someone else trying to develop a system using MCC’s DAQHATS. There are very little resources regarding using Daqhats from MCC from Matlab (unsupported) or MCC.
The installation of the DAQHAT python library requires that it be installed into a virtual environment. That was causing us issues expecially when we need to run 2 scripts back to back. It would close the virtual environment after the first script.
The following is the question we submitted to Matlab’s help team:
Description: We are using MCC Daqhats. First, I know this is not a supported hardware for Matlab. We are not asking for support for that. However, in the process of installing the python libraries for the Daqhats, we are forced to install them into a virtual environment. We believe this is causing us problems. We need to run multiple scripts in a row. We think that after the first call it is exiting the virtual environment but we are not certain of that.
The matlab file calling the python script is attached. The python script we are calling is attached. We have tested the python script on the PI and it runs properly both from python and the command line.
here is our Matlab error:
Error using datacollection
Error executing command "python3 /home/aset/daqhats/examples/python/mcc172/bert2.py". Details:
STDERR: Traceback (most recent call last):
File "/home/aset/daqhats/examples/python/mcc172/bert2.py", line 3, in <module>
from daqhats import mcc172, OptionFlags, SourceType, HatIDs, HatError
ModuleNotFoundError: No module named ‘daqhats’
Our Solution was as follows: (However others may have a better solution)
We have been able to get it to work by explicitly calling the virtual environment in the system command. This was found using a resource other than a Matlab site.
system(rpi, ‘/home/aset/environments/bin/python3 /home/aset/daqhats/examples/python/mcc172/bert2.py’) I’m posting this mostly as help to someone else trying to develop a system using MCC’s DAQHATS. There are very little resources regarding using Daqhats from MCC from Matlab (unsupported) or MCC.
The installation of the DAQHAT python library requires that it be installed into a virtual environment. That was causing us issues expecially when we need to run 2 scripts back to back. It would close the virtual environment after the first script.
The following is the question we submitted to Matlab’s help team:
Description: We are using MCC Daqhats. First, I know this is not a supported hardware for Matlab. We are not asking for support for that. However, in the process of installing the python libraries for the Daqhats, we are forced to install them into a virtual environment. We believe this is causing us problems. We need to run multiple scripts in a row. We think that after the first call it is exiting the virtual environment but we are not certain of that.
The matlab file calling the python script is attached. The python script we are calling is attached. We have tested the python script on the PI and it runs properly both from python and the command line.
here is our Matlab error:
Error using datacollection
Error executing command "python3 /home/aset/daqhats/examples/python/mcc172/bert2.py". Details:
STDERR: Traceback (most recent call last):
File "/home/aset/daqhats/examples/python/mcc172/bert2.py", line 3, in <module>
from daqhats import mcc172, OptionFlags, SourceType, HatIDs, HatError
ModuleNotFoundError: No module named ‘daqhats’
Our Solution was as follows: (However others may have a better solution)
We have been able to get it to work by explicitly calling the virtual environment in the system command. This was found using a resource other than a Matlab site.
system(rpi, ‘/home/aset/environments/bin/python3 /home/aset/daqhats/examples/python/mcc172/bert2.py’) mcc, daqhat, virtual enviroment MATLAB Answers — New Questions
Duffing equation:Transition to Chaos
The Original Equation is the following:
Let . This implies that
Then we eewrite it as a System of First-Order Equations
Using the substitution for , the second-order equation can be transformed into the following system of first-order equations:
Exploring the Effect of .
% Define parameters
gamma = 0.338;
alpha = -1;
beta = 1;
delta = 0.1;
omega = 1.4;
% Define the system of equations
odeSystem = @(t, y) [y(2);
-delta*y(2) – alpha*y(1) – beta*y(1)^3 + gamma*cos(omega*t)];
% Initial conditions
y0 = [0; 0]; % x(0) = 0, v(0) = 0
% Time span
tspan = [0 2000];
% Solve the system
[t, y] = ode45(odeSystem, tspan, y0);
% Plot the results
figure;
plot(t, y(:, 1));
xlabel(‘Time’);
ylabel(‘x(t)’);
title(‘Solution of the nonlinear system’);
grid on;
% Plot the phase portrait
figure;
plot(y(:, 1), y(:, 2));
xlabel(‘x(t)’);
ylabel(‘v(t)’);
title(‘Phase-Plane $$ddot{x}+delta dot{x}+alpha x+beta x^3=0$$ for $$gamma=0.318$$, $$alpha=-1$$,$$beta=1$$,$$delta=0.1$$,$$omega=1.4$$’,’Interpreter’, ‘latex’);
grid on;
% Define the tail (e.g., last 10% of the time interval)
tail_start = floor(0.9 * length(t)); % Starting index for the tail
tail_end = length(t); % Ending index for the tail
% Plot the tail of the solution
figure;
plot(y(tail_start:tail_end, 1), y(tail_start:tail_end, 2), ‘r’, ‘LineWidth’, 1.5);
xlabel(‘x(t)’);
ylabel(‘v(t)’);
title(‘Phase-Plane $$ddot{x}+delta dot{x}+alpha x+beta x^3=0$$ for $$gamma=0.318$$, $$alpha=-1$$,$$beta=1$$,$$delta=0.1$$,$$omega=1.4$$’,’Interpreter’, ‘latex’);
grid on;
ax = gca;
chart = ax.Children(1);
datatip(chart,0.5581,-0.1126);
Then I used but the results were not that I expected for
My code gives me the following. Any suggestion?
% Define parameters
gamma = 0.35;
alpha = -1;
beta = 1;
delta = 0.1;
omega = 1.4;
% Define the system of equations
odeSystem = @(t, y) [y(2);
-delta*y(2) – alpha*y(1) – beta*y(1)^3 + gamma*cos(omega*t)];
% Initial conditions
y0 = [0; 0]; % x(0) = 0, v(0) = 0
% Time span
tspan = [0 3000];
% Solve the system
[t, y] = ode45(odeSystem, tspan, y0);
% Plot the phase portrait
figure;
plot(y(:, 1), y(:, 2));
xlabel(‘x(t)’);
ylabel(‘v(t)’);
title(‘Phase-Plane $$ddot{x}+delta dot{x}+alpha x+beta x^3=0$$ for $$gamma=0.318$$, $$alpha=-1$$,$$beta=1$$,$$delta=0.1$$,$$omega=1.4$$’,’Interpreter’, ‘latex’);
grid on;
% Define the tail (e.g., last 10% of the time interval)
tail_start = floor(0.9 * length(t)); % Starting index for the tail
tail_end = length(t); % Ending index for the tail
% Plot the tail of the solution
figure;
plot(y(tail_start:tail_end, 1), y(tail_start:tail_end, 2), ‘r’, ‘LineWidth’, 1.5);
xlabel(‘x(t)’);
ylabel(‘v(t)’);
title(‘Phase-Plane $$ddot{x}+delta dot{x}+alpha x+beta x^3=0$$ for $$gamma=0.35$$, $$alpha=-1$$,$$beta=1$$,$$delta=0.1$$,$$omega=1.4$$’,’Interpreter’, ‘latex’);
grid on;
ax = gca;
chart = ax.Children(1);
datatip(chart,0.5581,-0.1126);The Original Equation is the following:
Let . This implies that
Then we eewrite it as a System of First-Order Equations
Using the substitution for , the second-order equation can be transformed into the following system of first-order equations:
Exploring the Effect of .
% Define parameters
gamma = 0.338;
alpha = -1;
beta = 1;
delta = 0.1;
omega = 1.4;
% Define the system of equations
odeSystem = @(t, y) [y(2);
-delta*y(2) – alpha*y(1) – beta*y(1)^3 + gamma*cos(omega*t)];
% Initial conditions
y0 = [0; 0]; % x(0) = 0, v(0) = 0
% Time span
tspan = [0 2000];
% Solve the system
[t, y] = ode45(odeSystem, tspan, y0);
% Plot the results
figure;
plot(t, y(:, 1));
xlabel(‘Time’);
ylabel(‘x(t)’);
title(‘Solution of the nonlinear system’);
grid on;
% Plot the phase portrait
figure;
plot(y(:, 1), y(:, 2));
xlabel(‘x(t)’);
ylabel(‘v(t)’);
title(‘Phase-Plane $$ddot{x}+delta dot{x}+alpha x+beta x^3=0$$ for $$gamma=0.318$$, $$alpha=-1$$,$$beta=1$$,$$delta=0.1$$,$$omega=1.4$$’,’Interpreter’, ‘latex’);
grid on;
% Define the tail (e.g., last 10% of the time interval)
tail_start = floor(0.9 * length(t)); % Starting index for the tail
tail_end = length(t); % Ending index for the tail
% Plot the tail of the solution
figure;
plot(y(tail_start:tail_end, 1), y(tail_start:tail_end, 2), ‘r’, ‘LineWidth’, 1.5);
xlabel(‘x(t)’);
ylabel(‘v(t)’);
title(‘Phase-Plane $$ddot{x}+delta dot{x}+alpha x+beta x^3=0$$ for $$gamma=0.318$$, $$alpha=-1$$,$$beta=1$$,$$delta=0.1$$,$$omega=1.4$$’,’Interpreter’, ‘latex’);
grid on;
ax = gca;
chart = ax.Children(1);
datatip(chart,0.5581,-0.1126);
Then I used but the results were not that I expected for
My code gives me the following. Any suggestion?
% Define parameters
gamma = 0.35;
alpha = -1;
beta = 1;
delta = 0.1;
omega = 1.4;
% Define the system of equations
odeSystem = @(t, y) [y(2);
-delta*y(2) – alpha*y(1) – beta*y(1)^3 + gamma*cos(omega*t)];
% Initial conditions
y0 = [0; 0]; % x(0) = 0, v(0) = 0
% Time span
tspan = [0 3000];
% Solve the system
[t, y] = ode45(odeSystem, tspan, y0);
% Plot the phase portrait
figure;
plot(y(:, 1), y(:, 2));
xlabel(‘x(t)’);
ylabel(‘v(t)’);
title(‘Phase-Plane $$ddot{x}+delta dot{x}+alpha x+beta x^3=0$$ for $$gamma=0.318$$, $$alpha=-1$$,$$beta=1$$,$$delta=0.1$$,$$omega=1.4$$’,’Interpreter’, ‘latex’);
grid on;
% Define the tail (e.g., last 10% of the time interval)
tail_start = floor(0.9 * length(t)); % Starting index for the tail
tail_end = length(t); % Ending index for the tail
% Plot the tail of the solution
figure;
plot(y(tail_start:tail_end, 1), y(tail_start:tail_end, 2), ‘r’, ‘LineWidth’, 1.5);
xlabel(‘x(t)’);
ylabel(‘v(t)’);
title(‘Phase-Plane $$ddot{x}+delta dot{x}+alpha x+beta x^3=0$$ for $$gamma=0.35$$, $$alpha=-1$$,$$beta=1$$,$$delta=0.1$$,$$omega=1.4$$’,’Interpreter’, ‘latex’);
grid on;
ax = gca;
chart = ax.Children(1);
datatip(chart,0.5581,-0.1126); The Original Equation is the following:
Let . This implies that
Then we eewrite it as a System of First-Order Equations
Using the substitution for , the second-order equation can be transformed into the following system of first-order equations:
Exploring the Effect of .
% Define parameters
gamma = 0.338;
alpha = -1;
beta = 1;
delta = 0.1;
omega = 1.4;
% Define the system of equations
odeSystem = @(t, y) [y(2);
-delta*y(2) – alpha*y(1) – beta*y(1)^3 + gamma*cos(omega*t)];
% Initial conditions
y0 = [0; 0]; % x(0) = 0, v(0) = 0
% Time span
tspan = [0 2000];
% Solve the system
[t, y] = ode45(odeSystem, tspan, y0);
% Plot the results
figure;
plot(t, y(:, 1));
xlabel(‘Time’);
ylabel(‘x(t)’);
title(‘Solution of the nonlinear system’);
grid on;
% Plot the phase portrait
figure;
plot(y(:, 1), y(:, 2));
xlabel(‘x(t)’);
ylabel(‘v(t)’);
title(‘Phase-Plane $$ddot{x}+delta dot{x}+alpha x+beta x^3=0$$ for $$gamma=0.318$$, $$alpha=-1$$,$$beta=1$$,$$delta=0.1$$,$$omega=1.4$$’,’Interpreter’, ‘latex’);
grid on;
% Define the tail (e.g., last 10% of the time interval)
tail_start = floor(0.9 * length(t)); % Starting index for the tail
tail_end = length(t); % Ending index for the tail
% Plot the tail of the solution
figure;
plot(y(tail_start:tail_end, 1), y(tail_start:tail_end, 2), ‘r’, ‘LineWidth’, 1.5);
xlabel(‘x(t)’);
ylabel(‘v(t)’);
title(‘Phase-Plane $$ddot{x}+delta dot{x}+alpha x+beta x^3=0$$ for $$gamma=0.318$$, $$alpha=-1$$,$$beta=1$$,$$delta=0.1$$,$$omega=1.4$$’,’Interpreter’, ‘latex’);
grid on;
ax = gca;
chart = ax.Children(1);
datatip(chart,0.5581,-0.1126);
Then I used but the results were not that I expected for
My code gives me the following. Any suggestion?
% Define parameters
gamma = 0.35;
alpha = -1;
beta = 1;
delta = 0.1;
omega = 1.4;
% Define the system of equations
odeSystem = @(t, y) [y(2);
-delta*y(2) – alpha*y(1) – beta*y(1)^3 + gamma*cos(omega*t)];
% Initial conditions
y0 = [0; 0]; % x(0) = 0, v(0) = 0
% Time span
tspan = [0 3000];
% Solve the system
[t, y] = ode45(odeSystem, tspan, y0);
% Plot the phase portrait
figure;
plot(y(:, 1), y(:, 2));
xlabel(‘x(t)’);
ylabel(‘v(t)’);
title(‘Phase-Plane $$ddot{x}+delta dot{x}+alpha x+beta x^3=0$$ for $$gamma=0.318$$, $$alpha=-1$$,$$beta=1$$,$$delta=0.1$$,$$omega=1.4$$’,’Interpreter’, ‘latex’);
grid on;
% Define the tail (e.g., last 10% of the time interval)
tail_start = floor(0.9 * length(t)); % Starting index for the tail
tail_end = length(t); % Ending index for the tail
% Plot the tail of the solution
figure;
plot(y(tail_start:tail_end, 1), y(tail_start:tail_end, 2), ‘r’, ‘LineWidth’, 1.5);
xlabel(‘x(t)’);
ylabel(‘v(t)’);
title(‘Phase-Plane $$ddot{x}+delta dot{x}+alpha x+beta x^3=0$$ for $$gamma=0.35$$, $$alpha=-1$$,$$beta=1$$,$$delta=0.1$$,$$omega=1.4$$’,’Interpreter’, ‘latex’);
grid on;
ax = gca;
chart = ax.Children(1);
datatip(chart,0.5581,-0.1126); ode45, duffing equation, plot, differential equations, plotting MATLAB Answers — New Questions
draw first principal component line 1 in the raw data
I have the data
WireLength 1 4 5 6 8 10 12 14 13 18 19 21
DieHeight 125 110 287 200 350 280 400 371 480 420 540 518
where Wirelength is the x variable and DieHeight is the y variable
I want to draw first and second principal component line in the raw data also draw the orthogonal lines from the point to the line.I have the data
WireLength 1 4 5 6 8 10 12 14 13 18 19 21
DieHeight 125 110 287 200 350 280 400 371 480 420 540 518
where Wirelength is the x variable and DieHeight is the y variable
I want to draw first and second principal component line in the raw data also draw the orthogonal lines from the point to the line. I have the data
WireLength 1 4 5 6 8 10 12 14 13 18 19 21
DieHeight 125 110 287 200 350 280 400 371 480 420 540 518
where Wirelength is the x variable and DieHeight is the y variable
I want to draw first and second principal component line in the raw data also draw the orthogonal lines from the point to the line. principal component analysis MATLAB Answers — New Questions
Is it possible to find the line-of-sight for coarsely spaced and uneven terrain data points?
Thank you for taking the time to help me with this. I’m using MATLAB R2024a. Here is my code:
% Create coarse-uneven data points
Xc = [5 7 11 17 27 40 59 82 129 191];
Yc = [-5 -2 2 0 3 -4 0 4 0 7];
% Basic parameters for observer and lines-of-sight
height = 5.2;
distance = 200;
radians = -pi/4:pi/24:0;
% Coordinates for intersecting lines
[X2, Y2] = pol2cart(radians, distance);
Y2 = Y2 + height;
X1 = zeros(size(X2));
Y1 = zeros(size(Y2)) + height;
% Plotting
figure
plot(Xc, Yc, ‘-r’)
hold on
plot([X1; X2], [Y1; Y2], ‘-b’)
hold off
As you can see, the x-component of the terrain is coarse and unevenly spaced. I would like to identify which terrain datapoints (Xc and Yc) are within line-of-sight of each "slice" of the observer’s vision. In the attached picture, there are four data points within the first sector of vision. It is likely that the second data point and most certainly the fourth data point would be obscured by the terrain pattern. How can I caluclate the line-of-sight for this and extract the Xc components that fall within line of sight of the observer who is positioned at x=0 and y=height?
Ideally, the output would be an NxM logical array where N is the number of vision sectors and M is the length of Xc. The values contained along M in the matrix would represent with boolean true/false values the indices of Xc in which (Xc,Yc) is visible by the observer for the Nth vision sector.
From what I’ve seen, los() and los2() take inputs in a much different format than just 2-D cartesian points and lines, so I haven’t been able to figure it out using those functions.
Once again, thank you for your time.Thank you for taking the time to help me with this. I’m using MATLAB R2024a. Here is my code:
% Create coarse-uneven data points
Xc = [5 7 11 17 27 40 59 82 129 191];
Yc = [-5 -2 2 0 3 -4 0 4 0 7];
% Basic parameters for observer and lines-of-sight
height = 5.2;
distance = 200;
radians = -pi/4:pi/24:0;
% Coordinates for intersecting lines
[X2, Y2] = pol2cart(radians, distance);
Y2 = Y2 + height;
X1 = zeros(size(X2));
Y1 = zeros(size(Y2)) + height;
% Plotting
figure
plot(Xc, Yc, ‘-r’)
hold on
plot([X1; X2], [Y1; Y2], ‘-b’)
hold off
As you can see, the x-component of the terrain is coarse and unevenly spaced. I would like to identify which terrain datapoints (Xc and Yc) are within line-of-sight of each "slice" of the observer’s vision. In the attached picture, there are four data points within the first sector of vision. It is likely that the second data point and most certainly the fourth data point would be obscured by the terrain pattern. How can I caluclate the line-of-sight for this and extract the Xc components that fall within line of sight of the observer who is positioned at x=0 and y=height?
Ideally, the output would be an NxM logical array where N is the number of vision sectors and M is the length of Xc. The values contained along M in the matrix would represent with boolean true/false values the indices of Xc in which (Xc,Yc) is visible by the observer for the Nth vision sector.
From what I’ve seen, los() and los2() take inputs in a much different format than just 2-D cartesian points and lines, so I haven’t been able to figure it out using those functions.
Once again, thank you for your time. Thank you for taking the time to help me with this. I’m using MATLAB R2024a. Here is my code:
% Create coarse-uneven data points
Xc = [5 7 11 17 27 40 59 82 129 191];
Yc = [-5 -2 2 0 3 -4 0 4 0 7];
% Basic parameters for observer and lines-of-sight
height = 5.2;
distance = 200;
radians = -pi/4:pi/24:0;
% Coordinates for intersecting lines
[X2, Y2] = pol2cart(radians, distance);
Y2 = Y2 + height;
X1 = zeros(size(X2));
Y1 = zeros(size(Y2)) + height;
% Plotting
figure
plot(Xc, Yc, ‘-r’)
hold on
plot([X1; X2], [Y1; Y2], ‘-b’)
hold off
As you can see, the x-component of the terrain is coarse and unevenly spaced. I would like to identify which terrain datapoints (Xc and Yc) are within line-of-sight of each "slice" of the observer’s vision. In the attached picture, there are four data points within the first sector of vision. It is likely that the second data point and most certainly the fourth data point would be obscured by the terrain pattern. How can I caluclate the line-of-sight for this and extract the Xc components that fall within line of sight of the observer who is positioned at x=0 and y=height?
Ideally, the output would be an NxM logical array where N is the number of vision sectors and M is the length of Xc. The values contained along M in the matrix would represent with boolean true/false values the indices of Xc in which (Xc,Yc) is visible by the observer for the Nth vision sector.
From what I’ve seen, los() and los2() take inputs in a much different format than just 2-D cartesian points and lines, so I haven’t been able to figure it out using those functions.
Once again, thank you for your time. los, line-of-sight, vectorization, geometry, geography, interpolation, vectors, surface, indexing, nonlinear, find, plot, signal processing MATLAB Answers — New Questions
Can I turn on the plot browser in a Matlab app?
I’m using the matlab app designer to create some plots and would like to add the plot browser so that I can hide/show certain data in the app. I am using 2024a and a cursory search on Google has turned up nothing.I’m using the matlab app designer to create some plots and would like to add the plot browser so that I can hide/show certain data in the app. I am using 2024a and a cursory search on Google has turned up nothing. I’m using the matlab app designer to create some plots and would like to add the plot browser so that I can hide/show certain data in the app. I am using 2024a and a cursory search on Google has turned up nothing. plotbrowser MATLAB Answers — New Questions
GPU Array Max Dimensions/Size (i.e., int32 of ~2e9) Not Same as Other CUDA-Enabled Languages (i.e., Python 3.9 – Tensorflow 2.11)
I would like to create Matlab GPU arrays that have a number of elements exceeding the max value of int32 (~2e9). In Matlab, when I try to do this, I get a "Max variable size exceeded" error. Other answers on this forum point to this limitation in GPU array size being caused by limitations in the CUDA API. However, I don’t believe this is accurate. Other languages, like Python 3.9 using theTensorflow 2.11 library for example, that are built on CUDA/CUBLAS allow for arrays that have a number of elements that exceed the MATLAB limitation.
Why is this the case, and why does Matlab seem limited where other languages are not?
The version of Matlab that I am using is 2024a, tested on both Win11 and Ubuntu 20.04LTS with a Nvidia Ada A6000 GPU (VRAM 48GB).
Matlab Code to reproduce:
g = gpuDevice();
arr = ones(1e4, 1e4, 60, ‘single’);
gpu_arr = gpuArray(arr);
Matlab ERROR:
Error using gpuArray
Maximum variable size allowed on the device is exceeded.
Python Code to reproduce:
import tensorflow as tf
arr = tf.ones([10000, 10000, 60])I would like to create Matlab GPU arrays that have a number of elements exceeding the max value of int32 (~2e9). In Matlab, when I try to do this, I get a "Max variable size exceeded" error. Other answers on this forum point to this limitation in GPU array size being caused by limitations in the CUDA API. However, I don’t believe this is accurate. Other languages, like Python 3.9 using theTensorflow 2.11 library for example, that are built on CUDA/CUBLAS allow for arrays that have a number of elements that exceed the MATLAB limitation.
Why is this the case, and why does Matlab seem limited where other languages are not?
The version of Matlab that I am using is 2024a, tested on both Win11 and Ubuntu 20.04LTS with a Nvidia Ada A6000 GPU (VRAM 48GB).
Matlab Code to reproduce:
g = gpuDevice();
arr = ones(1e4, 1e4, 60, ‘single’);
gpu_arr = gpuArray(arr);
Matlab ERROR:
Error using gpuArray
Maximum variable size allowed on the device is exceeded.
Python Code to reproduce:
import tensorflow as tf
arr = tf.ones([10000, 10000, 60]) I would like to create Matlab GPU arrays that have a number of elements exceeding the max value of int32 (~2e9). In Matlab, when I try to do this, I get a "Max variable size exceeded" error. Other answers on this forum point to this limitation in GPU array size being caused by limitations in the CUDA API. However, I don’t believe this is accurate. Other languages, like Python 3.9 using theTensorflow 2.11 library for example, that are built on CUDA/CUBLAS allow for arrays that have a number of elements that exceed the MATLAB limitation.
Why is this the case, and why does Matlab seem limited where other languages are not?
The version of Matlab that I am using is 2024a, tested on both Win11 and Ubuntu 20.04LTS with a Nvidia Ada A6000 GPU (VRAM 48GB).
Matlab Code to reproduce:
g = gpuDevice();
arr = ones(1e4, 1e4, 60, ‘single’);
gpu_arr = gpuArray(arr);
Matlab ERROR:
Error using gpuArray
Maximum variable size allowed on the device is exceeded.
Python Code to reproduce:
import tensorflow as tf
arr = tf.ones([10000, 10000, 60]) gpu, parallel computing toolbox, gpuarray, memory, vram, cuda, python MATLAB Answers — New Questions