Category: Matlab
Category Archives: Matlab
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
Simscape not showing assembly correctly in simulation
I imported my assembly from PTC Creo into Simscape and went to run it, but the assembly looks weird; nowhere like my assembly.
A screenshot of the two is below. Any suggestions?I imported my assembly from PTC Creo into Simscape and went to run it, but the assembly looks weird; nowhere like my assembly.
A screenshot of the two is below. Any suggestions? I imported my assembly from PTC Creo into Simscape and went to run it, but the assembly looks weird; nowhere like my assembly.
A screenshot of the two is below. Any suggestions? simscape, simulink, simulation MATLAB Answers — New Questions
how to put a bar above a letter in MATLAB equation?
I want to write letter x with bar above it but when I write $bar{x}$ it is not working in MATLAB online. Please I need your helpI want to write letter x with bar above it but when I write $bar{x}$ it is not working in MATLAB online. Please I need your help I want to write letter x with bar above it but when I write $bar{x}$ it is not working in MATLAB online. Please I need your help mathematics MATLAB Answers — New Questions
Finding NaN and Missing values from a mat cell matrix
Hello, I have obtained a global matrix from an analysis (which is attached here and it is a reduced matrix as it is exceeded the 5mb) and I would like to find the NaN and missing values for each case to sort out some issues in the code for those values before generating a more complex simulation analysis. As you will see in the mat file there are 70 columns with separate information and each row is identified by the 1st column as it is related to the unique event of my database. I would like to generate two tables with the following information:
1st table containing the summary information of NaN values values in the whole matrix (attched file, that it may not contain NaN values as I have to reduce the number of rows for exceeding the 5mb) where it provides their location based on the row (first column: date_event) that provides the date_event, the name of the station provided in colum 46, and the column of the variable that has the NaN value. For example:
matrix_NaN=[‘1985-03-03 22:47:08’, ‘CFLAN,’, ‘Rrup1’; ‘1997-02-19 18:25:14′,’CPLAT’, ‘Rx’; ……….]
2nd table containing the information of missing values like it was provided with the NaN values:
matrix_missing=[‘2003-08-26 21:11:35’, ‘CFLAN,’ ‘Rx’; ‘2003-08-26 21:11:35′,’CTRUJ’, sigma_Rx’; ……….]
I would appreciate the helpHello, I have obtained a global matrix from an analysis (which is attached here and it is a reduced matrix as it is exceeded the 5mb) and I would like to find the NaN and missing values for each case to sort out some issues in the code for those values before generating a more complex simulation analysis. As you will see in the mat file there are 70 columns with separate information and each row is identified by the 1st column as it is related to the unique event of my database. I would like to generate two tables with the following information:
1st table containing the summary information of NaN values values in the whole matrix (attched file, that it may not contain NaN values as I have to reduce the number of rows for exceeding the 5mb) where it provides their location based on the row (first column: date_event) that provides the date_event, the name of the station provided in colum 46, and the column of the variable that has the NaN value. For example:
matrix_NaN=[‘1985-03-03 22:47:08’, ‘CFLAN,’, ‘Rrup1’; ‘1997-02-19 18:25:14′,’CPLAT’, ‘Rx’; ……….]
2nd table containing the information of missing values like it was provided with the NaN values:
matrix_missing=[‘2003-08-26 21:11:35’, ‘CFLAN,’ ‘Rx’; ‘2003-08-26 21:11:35′,’CTRUJ’, sigma_Rx’; ……….]
I would appreciate the help Hello, I have obtained a global matrix from an analysis (which is attached here and it is a reduced matrix as it is exceeded the 5mb) and I would like to find the NaN and missing values for each case to sort out some issues in the code for those values before generating a more complex simulation analysis. As you will see in the mat file there are 70 columns with separate information and each row is identified by the 1st column as it is related to the unique event of my database. I would like to generate two tables with the following information:
1st table containing the summary information of NaN values values in the whole matrix (attched file, that it may not contain NaN values as I have to reduce the number of rows for exceeding the 5mb) where it provides their location based on the row (first column: date_event) that provides the date_event, the name of the station provided in colum 46, and the column of the variable that has the NaN value. For example:
matrix_NaN=[‘1985-03-03 22:47:08’, ‘CFLAN,’, ‘Rrup1’; ‘1997-02-19 18:25:14′,’CPLAT’, ‘Rx’; ……….]
2nd table containing the information of missing values like it was provided with the NaN values:
matrix_missing=[‘2003-08-26 21:11:35’, ‘CFLAN,’ ‘Rx’; ‘2003-08-26 21:11:35′,’CTRUJ’, sigma_Rx’; ……….]
I would appreciate the help finding nan and missing values from a cell matrix MATLAB Answers — New Questions
RF Budget Analyzer calculating noise figure incorrectly
I am currently using the RF Toolbox, to generate cascades using s-parameter files with the RF Budget Analyzer.
When I insert a passive component into the tool, It returns a noise figure value that is not equal to the negative of the Gain (Insertion loss in this case). Does anyone know what could cause this? This occurs even if I import a single S-parameter file, as the only part in the cascade.I am currently using the RF Toolbox, to generate cascades using s-parameter files with the RF Budget Analyzer.
When I insert a passive component into the tool, It returns a noise figure value that is not equal to the negative of the Gain (Insertion loss in this case). Does anyone know what could cause this? This occurs even if I import a single S-parameter file, as the only part in the cascade. I am currently using the RF Toolbox, to generate cascades using s-parameter files with the RF Budget Analyzer.
When I insert a passive component into the tool, It returns a noise figure value that is not equal to the negative of the Gain (Insertion loss in this case). Does anyone know what could cause this? This occurs even if I import a single S-parameter file, as the only part in the cascade. noise figure, rf budget analyzer, rf toolbox MATLAB Answers — New Questions
Add a title to a group of 4 subplots centred at the top
I have a group of subplots and want to add a title at the top, centre. How might one do this? Here is an MWE
subplot(2,2,1)
plot(peaks)
subplot(2,2,2)
plot(peaks)
subplot(2,2,3)
plot(peaks)
subplot(2,2,4)
plot(peaks)I have a group of subplots and want to add a title at the top, centre. How might one do this? Here is an MWE
subplot(2,2,1)
plot(peaks)
subplot(2,2,2)
plot(peaks)
subplot(2,2,3)
plot(peaks)
subplot(2,2,4)
plot(peaks) I have a group of subplots and want to add a title at the top, centre. How might one do this? Here is an MWE
subplot(2,2,1)
plot(peaks)
subplot(2,2,2)
plot(peaks)
subplot(2,2,3)
plot(peaks)
subplot(2,2,4)
plot(peaks) plotting, graphics MATLAB Answers — New Questions
what is ‘Derivative of state in block at time t is not finite. There may be a singularity in the solution.’ error? how to address it?
Hi
I am trying to simulate a thermal fluid system. As soon as I introduce gas-charged accumulator circled red in the circuit, it gives me following error
An error occurred while running the simulation and the simulation was terminated
Caused by:
Derivative of state ‘pumpandpipe13082024b.Gas_Charged_Accumulator_TL.T_I’ in block ‘pumpandpipe13082024b/Gas-Charged Accumulator (TL)’ at time 20.0 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)
Also, when I introduce elevation gain from port A to port B in pipes TL circled red, i have the following error
An error occurred while running the simulation and the simulation was terminated
Caused by:
Derivative of state ‘pumpandpipe13082024b.Centrifugal_Pump_TL1.A.T’ in block ‘pumpandpipe13082024b/Centrifugal Pump (TL)1’ at time 16.666666666666668 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)
what do these errors mean?Hi
I am trying to simulate a thermal fluid system. As soon as I introduce gas-charged accumulator circled red in the circuit, it gives me following error
An error occurred while running the simulation and the simulation was terminated
Caused by:
Derivative of state ‘pumpandpipe13082024b.Gas_Charged_Accumulator_TL.T_I’ in block ‘pumpandpipe13082024b/Gas-Charged Accumulator (TL)’ at time 20.0 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)
Also, when I introduce elevation gain from port A to port B in pipes TL circled red, i have the following error
An error occurred while running the simulation and the simulation was terminated
Caused by:
Derivative of state ‘pumpandpipe13082024b.Centrifugal_Pump_TL1.A.T’ in block ‘pumpandpipe13082024b/Centrifugal Pump (TL)1’ at time 16.666666666666668 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)
what do these errors mean? Hi
I am trying to simulate a thermal fluid system. As soon as I introduce gas-charged accumulator circled red in the circuit, it gives me following error
An error occurred while running the simulation and the simulation was terminated
Caused by:
Derivative of state ‘pumpandpipe13082024b.Gas_Charged_Accumulator_TL.T_I’ in block ‘pumpandpipe13082024b/Gas-Charged Accumulator (TL)’ at time 20.0 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)
Also, when I introduce elevation gain from port A to port B in pipes TL circled red, i have the following error
An error occurred while running the simulation and the simulation was terminated
Caused by:
Derivative of state ‘pumpandpipe13082024b.Centrifugal_Pump_TL1.A.T’ in block ‘pumpandpipe13082024b/Centrifugal Pump (TL)1’ at time 16.666666666666668 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)
what do these errors mean? simscape, error MATLAB Answers — New Questions
Why i am getting Error using Phase1/UIAxesButtonDown Too many input arguments.
Why i am getting Error using Phase1/UIAxesButtonDown Too many input arguments.Why i am getting Error using Phase1/UIAxesButtonDown Too many input arguments. Why i am getting Error using Phase1/UIAxesButtonDown Too many input arguments. matlab app designer MATLAB Answers — New Questions