Category: Matlab
Category Archives: Matlab
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
save animation in subplot
I’m using
while
drawnow;hold off
end
to create an animation. But this animation is just the 6th position as in subplot(2,3,6) (or through next tile repeatedly). To save this animation to the computer while not keeping the other subplots 1~5, what to do?I’m using
while
drawnow;hold off
end
to create an animation. But this animation is just the 6th position as in subplot(2,3,6) (or through next tile repeatedly). To save this animation to the computer while not keeping the other subplots 1~5, what to do? I’m using
while
drawnow;hold off
end
to create an animation. But this animation is just the 6th position as in subplot(2,3,6) (or through next tile repeatedly). To save this animation to the computer while not keeping the other subplots 1~5, what to do? drawnow, movie MATLAB Answers — New Questions
How can I increase the number of decimal places displayed on app designer UITable?
I am working on an app that ultimately produces 4 separate tables, each containing 4 columns of data. For simplicity, I am only including a single example, as I would think the process should be identical for all 4 tables, aside from the name of each table. All of the tables currently only show 4 decimal places. I would like to show more than this. I tried putting the following code in my startup function:
function startupFcn(app)
clc
close all
app.UITable.ColumnFormat = {‘long’,’long’,’long’,’long’}; %4x ‘long’ – 1 for each column?
This does not seem to work, as all of the tables still only display 4 decimal places. Any help would much appreciated. Thank you.I am working on an app that ultimately produces 4 separate tables, each containing 4 columns of data. For simplicity, I am only including a single example, as I would think the process should be identical for all 4 tables, aside from the name of each table. All of the tables currently only show 4 decimal places. I would like to show more than this. I tried putting the following code in my startup function:
function startupFcn(app)
clc
close all
app.UITable.ColumnFormat = {‘long’,’long’,’long’,’long’}; %4x ‘long’ – 1 for each column?
This does not seem to work, as all of the tables still only display 4 decimal places. Any help would much appreciated. Thank you. I am working on an app that ultimately produces 4 separate tables, each containing 4 columns of data. For simplicity, I am only including a single example, as I would think the process should be identical for all 4 tables, aside from the name of each table. All of the tables currently only show 4 decimal places. I would like to show more than this. I tried putting the following code in my startup function:
function startupFcn(app)
clc
close all
app.UITable.ColumnFormat = {‘long’,’long’,’long’,’long’}; %4x ‘long’ – 1 for each column?
This does not seem to work, as all of the tables still only display 4 decimal places. Any help would much appreciated. Thank you. appdesigner, uitable MATLAB Answers — New Questions
Plotting multiple datasets on one plot
I have a set of data for three replicate simulations: run0-run2, these consist of .dat files at a set time interval (here, every 100ns until final time 500ns).
I would like to plot these all on one plot but with a different colour gradient from darker to lighter e.g.
Run0 with a blue gradient dark to light as time increases.
Run1 with a green gradient dark to light as time increases.
Run2 with a red gradient dark to light as time increases.
I created the MATLAB script below but during testing, only the red plots would show up.
Combining into one for loop doesn’t work as I tried that already.
Any help would be greatly apreciated.
Code below and attached.
r0_f100=readmatrix (‘run0_test_fluct-100ns.dat’);
r0_f200=readmatrix (‘run0_test_fluct-200ns.dat’);
r0_f300=readmatrix (‘run0_test_fluct-300ns.dat’);
r0_f400=readmatrix (‘run0_test_fluct-400ns.dat’);
r0_f500=readmatrix (‘run0_test_fluct-500ns.dat’);
x_0=r0_f100(:,1);
y_0=[r0_f100(:,2),r0_f200(:,2),r0_f300(:,2),r0_f400(:,2),r0_f500(:,2)];
r1_f100=readmatrix (‘run1_test_fluct-100ns.dat’);
r1_f200=readmatrix (‘run1_test_fluct-200ns.dat’);
r1_f300=readmatrix (‘run1_test_fluct-300ns.dat’);
r1_f400=readmatrix (‘run1_test_fluct-400ns.dat’);
r1_f500=readmatrix (‘run1_test_fluct-500ns.dat’);
x_1=r1_f100(:,1);
y_1=[r1_f100(:,2),r1_f200(:,2),r1_f300(:,2),r1_f400(:,2),r1_f500(:,2)];
r2_f100=readmatrix (‘run2_test_fluct-100ns.dat’);
r2_f200=readmatrix (‘run2_test_fluct-200ns.dat’);
r2_f300=readmatrix (‘run2_test_fluct-300ns.dat’);
r2_f400=readmatrix (‘run2_test_fluct-400ns.dat’);
r2_f500=readmatrix (‘run2_test_fluct-500ns.dat’);
x_2=r2_f100(:,1);
y_2=[r2_f100(:,2),r2_f200(:,2),r2_f300(:,2),r2_f400(:,2),r2_f500(:,2)];
num_plots = 5;
colors = linspace(0.5, 1, num_plots)’;
figure
hold on
for i=1:num_plots
plot(x_0, y_0(:,i), ‘color’, [0 0 colors(i)]);
end
for i=1:num_plots
plot(x_1, y_1(:,i), ‘color’, [0 colors(i) 0]);
end
for i=1:num_plots
plot(x_2, y_2(:,i), ‘color’, [colors(i) 0 0]);
end
xlabel (‘Residue No.’); ylabel (‘RMSF / Å’);
ax = gca;
fig=gcf;
fig.Position(3:4)=[800,600];
fig.Color=[0.95 0.95 0.95];
ax.Color=[0.8 0.8 0.8];
hold off
%exportgraphics(fig,’test_RMSF.jpg’,’Resolution’,300);I have a set of data for three replicate simulations: run0-run2, these consist of .dat files at a set time interval (here, every 100ns until final time 500ns).
I would like to plot these all on one plot but with a different colour gradient from darker to lighter e.g.
Run0 with a blue gradient dark to light as time increases.
Run1 with a green gradient dark to light as time increases.
Run2 with a red gradient dark to light as time increases.
I created the MATLAB script below but during testing, only the red plots would show up.
Combining into one for loop doesn’t work as I tried that already.
Any help would be greatly apreciated.
Code below and attached.
r0_f100=readmatrix (‘run0_test_fluct-100ns.dat’);
r0_f200=readmatrix (‘run0_test_fluct-200ns.dat’);
r0_f300=readmatrix (‘run0_test_fluct-300ns.dat’);
r0_f400=readmatrix (‘run0_test_fluct-400ns.dat’);
r0_f500=readmatrix (‘run0_test_fluct-500ns.dat’);
x_0=r0_f100(:,1);
y_0=[r0_f100(:,2),r0_f200(:,2),r0_f300(:,2),r0_f400(:,2),r0_f500(:,2)];
r1_f100=readmatrix (‘run1_test_fluct-100ns.dat’);
r1_f200=readmatrix (‘run1_test_fluct-200ns.dat’);
r1_f300=readmatrix (‘run1_test_fluct-300ns.dat’);
r1_f400=readmatrix (‘run1_test_fluct-400ns.dat’);
r1_f500=readmatrix (‘run1_test_fluct-500ns.dat’);
x_1=r1_f100(:,1);
y_1=[r1_f100(:,2),r1_f200(:,2),r1_f300(:,2),r1_f400(:,2),r1_f500(:,2)];
r2_f100=readmatrix (‘run2_test_fluct-100ns.dat’);
r2_f200=readmatrix (‘run2_test_fluct-200ns.dat’);
r2_f300=readmatrix (‘run2_test_fluct-300ns.dat’);
r2_f400=readmatrix (‘run2_test_fluct-400ns.dat’);
r2_f500=readmatrix (‘run2_test_fluct-500ns.dat’);
x_2=r2_f100(:,1);
y_2=[r2_f100(:,2),r2_f200(:,2),r2_f300(:,2),r2_f400(:,2),r2_f500(:,2)];
num_plots = 5;
colors = linspace(0.5, 1, num_plots)’;
figure
hold on
for i=1:num_plots
plot(x_0, y_0(:,i), ‘color’, [0 0 colors(i)]);
end
for i=1:num_plots
plot(x_1, y_1(:,i), ‘color’, [0 colors(i) 0]);
end
for i=1:num_plots
plot(x_2, y_2(:,i), ‘color’, [colors(i) 0 0]);
end
xlabel (‘Residue No.’); ylabel (‘RMSF / Å’);
ax = gca;
fig=gcf;
fig.Position(3:4)=[800,600];
fig.Color=[0.95 0.95 0.95];
ax.Color=[0.8 0.8 0.8];
hold off
%exportgraphics(fig,’test_RMSF.jpg’,’Resolution’,300); I have a set of data for three replicate simulations: run0-run2, these consist of .dat files at a set time interval (here, every 100ns until final time 500ns).
I would like to plot these all on one plot but with a different colour gradient from darker to lighter e.g.
Run0 with a blue gradient dark to light as time increases.
Run1 with a green gradient dark to light as time increases.
Run2 with a red gradient dark to light as time increases.
I created the MATLAB script below but during testing, only the red plots would show up.
Combining into one for loop doesn’t work as I tried that already.
Any help would be greatly apreciated.
Code below and attached.
r0_f100=readmatrix (‘run0_test_fluct-100ns.dat’);
r0_f200=readmatrix (‘run0_test_fluct-200ns.dat’);
r0_f300=readmatrix (‘run0_test_fluct-300ns.dat’);
r0_f400=readmatrix (‘run0_test_fluct-400ns.dat’);
r0_f500=readmatrix (‘run0_test_fluct-500ns.dat’);
x_0=r0_f100(:,1);
y_0=[r0_f100(:,2),r0_f200(:,2),r0_f300(:,2),r0_f400(:,2),r0_f500(:,2)];
r1_f100=readmatrix (‘run1_test_fluct-100ns.dat’);
r1_f200=readmatrix (‘run1_test_fluct-200ns.dat’);
r1_f300=readmatrix (‘run1_test_fluct-300ns.dat’);
r1_f400=readmatrix (‘run1_test_fluct-400ns.dat’);
r1_f500=readmatrix (‘run1_test_fluct-500ns.dat’);
x_1=r1_f100(:,1);
y_1=[r1_f100(:,2),r1_f200(:,2),r1_f300(:,2),r1_f400(:,2),r1_f500(:,2)];
r2_f100=readmatrix (‘run2_test_fluct-100ns.dat’);
r2_f200=readmatrix (‘run2_test_fluct-200ns.dat’);
r2_f300=readmatrix (‘run2_test_fluct-300ns.dat’);
r2_f400=readmatrix (‘run2_test_fluct-400ns.dat’);
r2_f500=readmatrix (‘run2_test_fluct-500ns.dat’);
x_2=r2_f100(:,1);
y_2=[r2_f100(:,2),r2_f200(:,2),r2_f300(:,2),r2_f400(:,2),r2_f500(:,2)];
num_plots = 5;
colors = linspace(0.5, 1, num_plots)’;
figure
hold on
for i=1:num_plots
plot(x_0, y_0(:,i), ‘color’, [0 0 colors(i)]);
end
for i=1:num_plots
plot(x_1, y_1(:,i), ‘color’, [0 colors(i) 0]);
end
for i=1:num_plots
plot(x_2, y_2(:,i), ‘color’, [colors(i) 0 0]);
end
xlabel (‘Residue No.’); ylabel (‘RMSF / Å’);
ax = gca;
fig=gcf;
fig.Position(3:4)=[800,600];
fig.Color=[0.95 0.95 0.95];
ax.Color=[0.8 0.8 0.8];
hold off
%exportgraphics(fig,’test_RMSF.jpg’,’Resolution’,300); multiple datasets, plotting MATLAB Answers — New Questions
Image Processing Toolbox activated?
When I type into command window, license(‘test’, ‘image_toolbox’), it returns 1.
My code reads and displays images by imread, imshow. But it when I use mat2gray in the next line, there’s an error "’mat2gray’ requires Image Processing Toolbox."When I type into command window, license(‘test’, ‘image_toolbox’), it returns 1.
My code reads and displays images by imread, imshow. But it when I use mat2gray in the next line, there’s an error "’mat2gray’ requires Image Processing Toolbox." When I type into command window, license(‘test’, ‘image_toolbox’), it returns 1.
My code reads and displays images by imread, imshow. But it when I use mat2gray in the next line, there’s an error "’mat2gray’ requires Image Processing Toolbox." image-processing toolbox MATLAB Answers — New Questions
Open a picture when an object is clicked.
I would like to attach an object (or something) next to a block that would open a picture when someone clicks on the object. I don’t have a lot of space on my model but I think it would be helpful if someone could click on an object to show a picture of the actual piece of equipment.I would like to attach an object (or something) next to a block that would open a picture when someone clicks on the object. I don’t have a lot of space on my model but I think it would be helpful if someone could click on an object to show a picture of the actual piece of equipment. I would like to attach an object (or something) next to a block that would open a picture when someone clicks on the object. I don’t have a lot of space on my model but I think it would be helpful if someone could click on an object to show a picture of the actual piece of equipment. show picture MATLAB Answers — New Questions
I want to export my variabels to a single .nc file
Hello.
I have a set of variables that i want to export as one .nc file so that i can use the dataset later on. I have tried using the instructions listed in this thread but it keeps returning an error. I’ll include my code and the variables that i use below. And sorry for the rudamentary code, I’m still new to matlab
clear
clc
%masukin waktu
waktu= ncread(‘FABMSAT.nc’,’time’);
waktu= waktu’;
%masukin fito layer 1
fito= ncread(‘FABMSAT.nc’,’npzd_phy’);
fito= fito(:,1,:);
%masukin pasut
pasut= ncread(‘FABMSAT.nc’,’zeta’);
% masukin vector u
u= ncread(‘FABMSAT.nc’,’u’);
u= u(:,1,:);
%Masukin vector v
v= ncread(‘FABMSAT.nc’,’u’);
v= v(:,1,:);
%CUT SUPAYA MULAI 1 FEB 2022
waktu_feb= waktu;
waktu_feb(:,[1:168])=[];
fito_feb= fito;
fito_feb(:,[1:168])=[];
pasut_feb= pasut;
pasut_feb([2:8307],:)=[];
u_feb= u;
u_feb(:,[1:168])=[];
v_feb= v;
v_feb(:,[1:168])=[];
%define dimensions
netcdf.setDefaultFormat(‘NC_FORMAT_CLASSIC’);
ncid = netcdf.create(‘test.nc’,’NC_WRITE’);
dimidfito = netcdf.defDim(ncid,’fito_feb’,fito_feb);
%Define the name of variable
var_fito = netcdf.defVar(ncid, ‘fito_feb’,’NC_FLOAT’,[dimidfito]);
%variables into .nc file
netcdf.endDef(ncid);
netcdf.putVar(ncid,var_fito,fito_feb);
netcdf.close(ncid);Hello.
I have a set of variables that i want to export as one .nc file so that i can use the dataset later on. I have tried using the instructions listed in this thread but it keeps returning an error. I’ll include my code and the variables that i use below. And sorry for the rudamentary code, I’m still new to matlab
clear
clc
%masukin waktu
waktu= ncread(‘FABMSAT.nc’,’time’);
waktu= waktu’;
%masukin fito layer 1
fito= ncread(‘FABMSAT.nc’,’npzd_phy’);
fito= fito(:,1,:);
%masukin pasut
pasut= ncread(‘FABMSAT.nc’,’zeta’);
% masukin vector u
u= ncread(‘FABMSAT.nc’,’u’);
u= u(:,1,:);
%Masukin vector v
v= ncread(‘FABMSAT.nc’,’u’);
v= v(:,1,:);
%CUT SUPAYA MULAI 1 FEB 2022
waktu_feb= waktu;
waktu_feb(:,[1:168])=[];
fito_feb= fito;
fito_feb(:,[1:168])=[];
pasut_feb= pasut;
pasut_feb([2:8307],:)=[];
u_feb= u;
u_feb(:,[1:168])=[];
v_feb= v;
v_feb(:,[1:168])=[];
%define dimensions
netcdf.setDefaultFormat(‘NC_FORMAT_CLASSIC’);
ncid = netcdf.create(‘test.nc’,’NC_WRITE’);
dimidfito = netcdf.defDim(ncid,’fito_feb’,fito_feb);
%Define the name of variable
var_fito = netcdf.defVar(ncid, ‘fito_feb’,’NC_FLOAT’,[dimidfito]);
%variables into .nc file
netcdf.endDef(ncid);
netcdf.putVar(ncid,var_fito,fito_feb);
netcdf.close(ncid); Hello.
I have a set of variables that i want to export as one .nc file so that i can use the dataset later on. I have tried using the instructions listed in this thread but it keeps returning an error. I’ll include my code and the variables that i use below. And sorry for the rudamentary code, I’m still new to matlab
clear
clc
%masukin waktu
waktu= ncread(‘FABMSAT.nc’,’time’);
waktu= waktu’;
%masukin fito layer 1
fito= ncread(‘FABMSAT.nc’,’npzd_phy’);
fito= fito(:,1,:);
%masukin pasut
pasut= ncread(‘FABMSAT.nc’,’zeta’);
% masukin vector u
u= ncread(‘FABMSAT.nc’,’u’);
u= u(:,1,:);
%Masukin vector v
v= ncread(‘FABMSAT.nc’,’u’);
v= v(:,1,:);
%CUT SUPAYA MULAI 1 FEB 2022
waktu_feb= waktu;
waktu_feb(:,[1:168])=[];
fito_feb= fito;
fito_feb(:,[1:168])=[];
pasut_feb= pasut;
pasut_feb([2:8307],:)=[];
u_feb= u;
u_feb(:,[1:168])=[];
v_feb= v;
v_feb(:,[1:168])=[];
%define dimensions
netcdf.setDefaultFormat(‘NC_FORMAT_CLASSIC’);
ncid = netcdf.create(‘test.nc’,’NC_WRITE’);
dimidfito = netcdf.defDim(ncid,’fito_feb’,fito_feb);
%Define the name of variable
var_fito = netcdf.defVar(ncid, ‘fito_feb’,’NC_FLOAT’,[dimidfito]);
%variables into .nc file
netcdf.endDef(ncid);
netcdf.putVar(ncid,var_fito,fito_feb);
netcdf.close(ncid); export, netcdf MATLAB Answers — New Questions
allmargin gives incorrect answers for some discrete time systems
Hi,
Consider the following code:
s = tf("s");
gs = 1/(s*(s+1));
gz = c2d(gs, 4, "zoh");
allmargin(gz)
gclz = zpk(feedback(gz,1,-1));
abs(gclz.P{1})
In R2024a, the stable flag given by allmargin is equal to one, indicating that the closed loop system is stable. On the other hand, the last sentence of the above code shows that the closed-loop system has a pole outside the unit circle, and therefore it is unstable. I do not have this issue in R2022b. Why the difference?
Sincerely
CarlosHi,
Consider the following code:
s = tf("s");
gs = 1/(s*(s+1));
gz = c2d(gs, 4, "zoh");
allmargin(gz)
gclz = zpk(feedback(gz,1,-1));
abs(gclz.P{1})
In R2024a, the stable flag given by allmargin is equal to one, indicating that the closed loop system is stable. On the other hand, the last sentence of the above code shows that the closed-loop system has a pole outside the unit circle, and therefore it is unstable. I do not have this issue in R2022b. Why the difference?
Sincerely
Carlos Hi,
Consider the following code:
s = tf("s");
gs = 1/(s*(s+1));
gz = c2d(gs, 4, "zoh");
allmargin(gz)
gclz = zpk(feedback(gz,1,-1));
abs(gclz.P{1})
In R2024a, the stable flag given by allmargin is equal to one, indicating that the closed loop system is stable. On the other hand, the last sentence of the above code shows that the closed-loop system has a pole outside the unit circle, and therefore it is unstable. I do not have this issue in R2022b. Why the difference?
Sincerely
Carlos allmargin MATLAB Answers — New Questions
i am getting when trying to 6th order dynamic equation uisng matlab function in simulink, ‘
Derivative of state ‘1’ in block ‘Fccu_matlabFcn/Integrator2’ at time 0.042441271689357414 is not finite. The simulation will be stopped. There may be a singularity in the solution. If not, try reducing the step size (either by reducing the fixed step size or by tightening the error tolerances)Derivative of state ‘1’ in block ‘Fccu_matlabFcn/Integrator2’ at time 0.042441271689357414 is not finite. The simulation will be stopped. There may be a singularity in the solution. If not, try reducing the step size (either by reducing the fixed step size or by tightening the error tolerances) Derivative of state ‘1’ in block ‘Fccu_matlabFcn/Integrator2’ at time 0.042441271689357414 is not finite. The simulation will be stopped. There may be a singularity in the solution. If not, try reducing the step size (either by reducing the fixed step size or by tightening the error tolerances) error tolerances MATLAB Answers — New Questions
Please, I need to express the following equations to get the value of M_tot. I write the equations and successfully ran the code but the result is not what I had anticipated.
Please help, I need to express the following equations to get the value of M_tot. I have already written the relevant equations and successfully ran the code, but the result is not what I had anticipated. Would you kindly examine the following code and compare it with the equations for the system?
Sf = 0.01;
Mo = 4*pi*10^-7 ;
Mr = 3200;
Fr= 85000;
w = 2*pi*Fr;
t_TX = 0.01;
t_RX = 0.02;
rs = 0.00006;
r_TX = 17.32*1.58*rs;
r_RX = 17.32*1.58*rs;
R_TX = 0.045;
R_RX = 0.045;
h = 0.3;
d_TX = 0.01;
d_RX = 0.01;
N_TX = 10;
N_RX = 10;
s = 0.005;
Func = 0;
M_fer = 0;
M_air = 0;
syms k
syms x
i
f1 = sqrt ((k^2)+i*(w*Mo*Mr*Sf));
f2 = (Mr-(f1/k))/(Mr+(f1/k));
f3_TX = f2*(1-exp(-2*f1*t_TX)) / (1-((f2)^2)*(exp(-2*f1*t_TX)));
f3_RX = f2*(1-exp(-2*f1*t_RX)) / (1-((f2)^2)*(exp(-2*f1*t_RX)));
f4 = ((f3_TX)*exp(-k*((2*r_TX) + r_RX + h + d_RX)) + (f3_RX * exp(-k*((2*r_RX) + r_TX + h + d_TX))))/(1 – (f3_TX * f3_RX * exp(-k*((2*r_TX) + (2*r_RX) + h + d_TX + d_RX))));
f5 = (2 * f3_TX * f3_RX * exp(-k*((2*r_TX) + (2*r_RX) + h + d_TX + d_RX)) * cosh(k*(r_TX + r_RX + h))) / (1 – (f3_TX * f3_RX * exp(-k*((2*r_TX) + (2*r_RX) + h + d_TX + d_RX))));
for i = 1:N_TX
R_TXn = R_TX + (N_TX – 1)*(s+ 2*r_TX);
for j = 1:N_RX
R_RXn = R_RX + (N_RX – 1)*(s+ 2*r_RX);
Func = @(k) Mo.*pi.*R_TXn.*R_RXn.* ( besselj(1,(R_TXn.*k)) .* besselj(1,(R_RXn.*k)) .* (f4 + f5));
M_fer = vpaintegral(Func(k),k,0,inf);
f = sqrt ((4.*R_TXn.*R_RXn)./ ((r_TX + r_RX + h)^2 +(R_TXn + R_RXn)^2) );
[K_f,E_f] = ellipke(f);
M_air = Mo.*sqrt(R_TXn.*R_RXn).*(2./f).*((1-0.5.*(f^2)).*(K_f) – E_f) ;
end
end
M_tot = M_fer + M_airPlease help, I need to express the following equations to get the value of M_tot. I have already written the relevant equations and successfully ran the code, but the result is not what I had anticipated. Would you kindly examine the following code and compare it with the equations for the system?
Sf = 0.01;
Mo = 4*pi*10^-7 ;
Mr = 3200;
Fr= 85000;
w = 2*pi*Fr;
t_TX = 0.01;
t_RX = 0.02;
rs = 0.00006;
r_TX = 17.32*1.58*rs;
r_RX = 17.32*1.58*rs;
R_TX = 0.045;
R_RX = 0.045;
h = 0.3;
d_TX = 0.01;
d_RX = 0.01;
N_TX = 10;
N_RX = 10;
s = 0.005;
Func = 0;
M_fer = 0;
M_air = 0;
syms k
syms x
i
f1 = sqrt ((k^2)+i*(w*Mo*Mr*Sf));
f2 = (Mr-(f1/k))/(Mr+(f1/k));
f3_TX = f2*(1-exp(-2*f1*t_TX)) / (1-((f2)^2)*(exp(-2*f1*t_TX)));
f3_RX = f2*(1-exp(-2*f1*t_RX)) / (1-((f2)^2)*(exp(-2*f1*t_RX)));
f4 = ((f3_TX)*exp(-k*((2*r_TX) + r_RX + h + d_RX)) + (f3_RX * exp(-k*((2*r_RX) + r_TX + h + d_TX))))/(1 – (f3_TX * f3_RX * exp(-k*((2*r_TX) + (2*r_RX) + h + d_TX + d_RX))));
f5 = (2 * f3_TX * f3_RX * exp(-k*((2*r_TX) + (2*r_RX) + h + d_TX + d_RX)) * cosh(k*(r_TX + r_RX + h))) / (1 – (f3_TX * f3_RX * exp(-k*((2*r_TX) + (2*r_RX) + h + d_TX + d_RX))));
for i = 1:N_TX
R_TXn = R_TX + (N_TX – 1)*(s+ 2*r_TX);
for j = 1:N_RX
R_RXn = R_RX + (N_RX – 1)*(s+ 2*r_RX);
Func = @(k) Mo.*pi.*R_TXn.*R_RXn.* ( besselj(1,(R_TXn.*k)) .* besselj(1,(R_RXn.*k)) .* (f4 + f5));
M_fer = vpaintegral(Func(k),k,0,inf);
f = sqrt ((4.*R_TXn.*R_RXn)./ ((r_TX + r_RX + h)^2 +(R_TXn + R_RXn)^2) );
[K_f,E_f] = ellipke(f);
M_air = Mo.*sqrt(R_TXn.*R_RXn).*(2./f).*((1-0.5.*(f^2)).*(K_f) – E_f) ;
end
end
M_tot = M_fer + M_air Please help, I need to express the following equations to get the value of M_tot. I have already written the relevant equations and successfully ran the code, but the result is not what I had anticipated. Would you kindly examine the following code and compare it with the equations for the system?
Sf = 0.01;
Mo = 4*pi*10^-7 ;
Mr = 3200;
Fr= 85000;
w = 2*pi*Fr;
t_TX = 0.01;
t_RX = 0.02;
rs = 0.00006;
r_TX = 17.32*1.58*rs;
r_RX = 17.32*1.58*rs;
R_TX = 0.045;
R_RX = 0.045;
h = 0.3;
d_TX = 0.01;
d_RX = 0.01;
N_TX = 10;
N_RX = 10;
s = 0.005;
Func = 0;
M_fer = 0;
M_air = 0;
syms k
syms x
i
f1 = sqrt ((k^2)+i*(w*Mo*Mr*Sf));
f2 = (Mr-(f1/k))/(Mr+(f1/k));
f3_TX = f2*(1-exp(-2*f1*t_TX)) / (1-((f2)^2)*(exp(-2*f1*t_TX)));
f3_RX = f2*(1-exp(-2*f1*t_RX)) / (1-((f2)^2)*(exp(-2*f1*t_RX)));
f4 = ((f3_TX)*exp(-k*((2*r_TX) + r_RX + h + d_RX)) + (f3_RX * exp(-k*((2*r_RX) + r_TX + h + d_TX))))/(1 – (f3_TX * f3_RX * exp(-k*((2*r_TX) + (2*r_RX) + h + d_TX + d_RX))));
f5 = (2 * f3_TX * f3_RX * exp(-k*((2*r_TX) + (2*r_RX) + h + d_TX + d_RX)) * cosh(k*(r_TX + r_RX + h))) / (1 – (f3_TX * f3_RX * exp(-k*((2*r_TX) + (2*r_RX) + h + d_TX + d_RX))));
for i = 1:N_TX
R_TXn = R_TX + (N_TX – 1)*(s+ 2*r_TX);
for j = 1:N_RX
R_RXn = R_RX + (N_RX – 1)*(s+ 2*r_RX);
Func = @(k) Mo.*pi.*R_TXn.*R_RXn.* ( besselj(1,(R_TXn.*k)) .* besselj(1,(R_RXn.*k)) .* (f4 + f5));
M_fer = vpaintegral(Func(k),k,0,inf);
f = sqrt ((4.*R_TXn.*R_RXn)./ ((r_TX + r_RX + h)^2 +(R_TXn + R_RXn)^2) );
[K_f,E_f] = ellipke(f);
M_air = Mo.*sqrt(R_TXn.*R_RXn).*(2./f).*((1-0.5.*(f^2)).*(K_f) – E_f) ;
end
end
M_tot = M_fer + M_air mutual_inductance MATLAB Answers — New Questions