Tag Archives: matlab
How to plot the input which is R for LQR?
I am getting 2 outputs my system is inverted pendulum with 4 states.
How can I get the input plot the value of R as well?
further I am gettign only two states the cart position and teh angle of the penduum. How I can plot the other two states velocity and angular velocity in teh same plot where I am getting the position and the pendulum angle?I am getting 2 outputs my system is inverted pendulum with 4 states.
How can I get the input plot the value of R as well?
further I am gettign only two states the cart position and teh angle of the penduum. How I can plot the other two states velocity and angular velocity in teh same plot where I am getting the position and the pendulum angle? I am getting 2 outputs my system is inverted pendulum with 4 states.
How can I get the input plot the value of R as well?
further I am gettign only two states the cart position and teh angle of the penduum. How I can plot the other two states velocity and angular velocity in teh same plot where I am getting the position and the pendulum angle? lqr, inverted pendulum, plotting, subplot MATLAB Answers — New Questions
How to apply NonNegativity constraint in ODE solver when defining ode as a structure
I am trying to perform a local sensitivity analysis on the parameters of my model using odeSensitivity. Taking help from this page https://in.mathworks.com/help/matlab/ref/odesensitivity.html. but the problem is that when I used to code the ode simply I put nonnegativity under options, but now i am not able to do that. I tried taking F.NonNegative=ones(1,n_parameters) but that doesnt seem to work.I am trying to perform a local sensitivity analysis on the parameters of my model using odeSensitivity. Taking help from this page https://in.mathworks.com/help/matlab/ref/odesensitivity.html. but the problem is that when I used to code the ode simply I put nonnegativity under options, but now i am not able to do that. I tried taking F.NonNegative=ones(1,n_parameters) but that doesnt seem to work. I am trying to perform a local sensitivity analysis on the parameters of my model using odeSensitivity. Taking help from this page https://in.mathworks.com/help/matlab/ref/odesensitivity.html. but the problem is that when I used to code the ode simply I put nonnegativity under options, but now i am not able to do that. I tried taking F.NonNegative=ones(1,n_parameters) but that doesnt seem to work. ode, structures MATLAB Answers — New Questions
Matlab onramp course blank screen
I’m trying to do my Matlab onramp course but when i try enter commands the screen is completely blank, and i can’t do anything.I’m trying to do my Matlab onramp course but when i try enter commands the screen is completely blank, and i can’t do anything. I’m trying to do my Matlab onramp course but when i try enter commands the screen is completely blank, and i can’t do anything. matlab, onramp, commands MATLAB Answers — New Questions
Plot contours from counts of a scatter plot
Hi everyone, I’m fairly new to Matlab and i’m not sure how to obtain what i what i want.
I made this graphics where i’m trying to match some datas with my simulation. The prolem is that i’m simulating thtat same amounts of point as the ones in the data set (about 100) but has some statistic problems. So i wanted to simulate more points (about 1000) to use contour lines to show where i have different density of simulated points. This is where i ran into trubles.
I looked into the contour(Z) function, but i’m not sure how to make the Z matrix. I have two vectors, x and y, with the coordinates of my simulated point (and anoters set of twwo vectors for the datas).
I was thinking about using something lixe this to:
Z = histcounts2(x, y, ‘BinWidth’, [n, n], ‘XBinLimits’, [x1 x2], ‘YBinLimits’, [y1 y2])
But I’m not sure wich BinWidht to use to obtain what I want, or even if ot’s the best way to go about it.
Any pointers would be really appreciated,
Thakns to allHi everyone, I’m fairly new to Matlab and i’m not sure how to obtain what i what i want.
I made this graphics where i’m trying to match some datas with my simulation. The prolem is that i’m simulating thtat same amounts of point as the ones in the data set (about 100) but has some statistic problems. So i wanted to simulate more points (about 1000) to use contour lines to show where i have different density of simulated points. This is where i ran into trubles.
I looked into the contour(Z) function, but i’m not sure how to make the Z matrix. I have two vectors, x and y, with the coordinates of my simulated point (and anoters set of twwo vectors for the datas).
I was thinking about using something lixe this to:
Z = histcounts2(x, y, ‘BinWidth’, [n, n], ‘XBinLimits’, [x1 x2], ‘YBinLimits’, [y1 y2])
But I’m not sure wich BinWidht to use to obtain what I want, or even if ot’s the best way to go about it.
Any pointers would be really appreciated,
Thakns to all Hi everyone, I’m fairly new to Matlab and i’m not sure how to obtain what i what i want.
I made this graphics where i’m trying to match some datas with my simulation. The prolem is that i’m simulating thtat same amounts of point as the ones in the data set (about 100) but has some statistic problems. So i wanted to simulate more points (about 1000) to use contour lines to show where i have different density of simulated points. This is where i ran into trubles.
I looked into the contour(Z) function, but i’m not sure how to make the Z matrix. I have two vectors, x and y, with the coordinates of my simulated point (and anoters set of twwo vectors for the datas).
I was thinking about using something lixe this to:
Z = histcounts2(x, y, ‘BinWidth’, [n, n], ‘XBinLimits’, [x1 x2], ‘YBinLimits’, [y1 y2])
But I’m not sure wich BinWidht to use to obtain what I want, or even if ot’s the best way to go about it.
Any pointers would be really appreciated,
Thakns to all ‘countours’ ‘contour plot’ ‘histcounts’ ‘counts’ MATLAB Answers — New Questions
Amplitude White noise in Simulink Matlab
I want to add colored noise to the step signal when I use White noise inside Simulink it has 1/-1 amplitude I want to reduce this amplitude like pink noise which has 0.05/-0.05 amplitude
white noise
pink noiseI want to add colored noise to the step signal when I use White noise inside Simulink it has 1/-1 amplitude I want to reduce this amplitude like pink noise which has 0.05/-0.05 amplitude
white noise
pink noise I want to add colored noise to the step signal when I use White noise inside Simulink it has 1/-1 amplitude I want to reduce this amplitude like pink noise which has 0.05/-0.05 amplitude
white noise
pink noise noise, pinknoise, whitenoise MATLAB Answers — New Questions
How can I save my figure to eps AND keep white margins (from my defined figure and axes position)?
I am producing multiple figures which I then need to vertically align in latex. I set my figure and axes position like this:
% Set figure total dimension
set(gcf,’Units’,’centimeters’)
set(gcf,’Position’,[0 0 4.5 5.8])
% Set size and position of axes plotting area within figure dimensions. To
% keep vertical axes aligned for multiple figure keep the horizontal
% position consistent
set(gca,’Units’,’centimeters’)
set(gca, ‘Position’,[1.5 1.3 2.85 4])
Some of my figures have a ylabel and some don’t, which thanks to the above set position does not affect the format of the figure. However when I save my figure to eps using
saveas(gcf,’filename’,’epsc’)
the eps file saves it as the tightest fit, ignoring my set positions. How can I get it to save whilst conserving my set formatting?
I’ve tried saving to .png but the quality is massively reduced (even when using the package export_fig). Is there a simple solution?
I am on MacOs.I am producing multiple figures which I then need to vertically align in latex. I set my figure and axes position like this:
% Set figure total dimension
set(gcf,’Units’,’centimeters’)
set(gcf,’Position’,[0 0 4.5 5.8])
% Set size and position of axes plotting area within figure dimensions. To
% keep vertical axes aligned for multiple figure keep the horizontal
% position consistent
set(gca,’Units’,’centimeters’)
set(gca, ‘Position’,[1.5 1.3 2.85 4])
Some of my figures have a ylabel and some don’t, which thanks to the above set position does not affect the format of the figure. However when I save my figure to eps using
saveas(gcf,’filename’,’epsc’)
the eps file saves it as the tightest fit, ignoring my set positions. How can I get it to save whilst conserving my set formatting?
I’ve tried saving to .png but the quality is massively reduced (even when using the package export_fig). Is there a simple solution?
I am on MacOs. I am producing multiple figures which I then need to vertically align in latex. I set my figure and axes position like this:
% Set figure total dimension
set(gcf,’Units’,’centimeters’)
set(gcf,’Position’,[0 0 4.5 5.8])
% Set size and position of axes plotting area within figure dimensions. To
% keep vertical axes aligned for multiple figure keep the horizontal
% position consistent
set(gca,’Units’,’centimeters’)
set(gca, ‘Position’,[1.5 1.3 2.85 4])
Some of my figures have a ylabel and some don’t, which thanks to the above set position does not affect the format of the figure. However when I save my figure to eps using
saveas(gcf,’filename’,’epsc’)
the eps file saves it as the tightest fit, ignoring my set positions. How can I get it to save whilst conserving my set formatting?
I’ve tried saving to .png but the quality is massively reduced (even when using the package export_fig). Is there a simple solution?
I am on MacOs. saveas, eps, nocrop, vertical alignement, figure position, export MATLAB Answers — New Questions
License Manager Error -9 Your username does not match the username in the license file.
License checkout failed.
License Manager Error -9
Your username does not match the username in the license file.
To run on this computer, you must run the Activation client to reactivate your license.
Troubleshoot this issue by visiting:
https://www.mathworks.com/support/lme/R2019b/9
Diagnostic Information:
Feature: MATLAB
License path: /home/alex/.matlab/R2019b_licenses:/usr/local/MATLAB/R2019b/licenses/license.dat:/usr/local/MATLAB/R
2019b/licenses/license_thinkpad-p73_40871338_R2019b.lic
Licensing error: -9,57.
I am a student, I want to install the matlab under Ubuntu, but always get this problem??why is the matlab so unfrienddly to the users??License checkout failed.
License Manager Error -9
Your username does not match the username in the license file.
To run on this computer, you must run the Activation client to reactivate your license.
Troubleshoot this issue by visiting:
https://www.mathworks.com/support/lme/R2019b/9
Diagnostic Information:
Feature: MATLAB
License path: /home/alex/.matlab/R2019b_licenses:/usr/local/MATLAB/R2019b/licenses/license.dat:/usr/local/MATLAB/R
2019b/licenses/license_thinkpad-p73_40871338_R2019b.lic
Licensing error: -9,57.
I am a student, I want to install the matlab under Ubuntu, but always get this problem??why is the matlab so unfrienddly to the users?? License checkout failed.
License Manager Error -9
Your username does not match the username in the license file.
To run on this computer, you must run the Activation client to reactivate your license.
Troubleshoot this issue by visiting:
https://www.mathworks.com/support/lme/R2019b/9
Diagnostic Information:
Feature: MATLAB
License path: /home/alex/.matlab/R2019b_licenses:/usr/local/MATLAB/R2019b/licenses/license.dat:/usr/local/MATLAB/R
2019b/licenses/license_thinkpad-p73_40871338_R2019b.lic
Licensing error: -9,57.
I am a student, I want to install the matlab under Ubuntu, but always get this problem??why is the matlab so unfrienddly to the users?? ubuntu MATLAB Answers — New Questions
How can I integrate RTOS in stm32F407XX automatic code generation?
Hi, I’m trying to integrate the Real Time Operating System capability for the Stm32f407vg discovery board Target by automatic generation code of a simulink model.
I found "ST Discovery Board Support from Embedded Coder" that is based on STM32 Standard Peripheral Libraries, but I use the Simulink+STM32CubeMx+Keil5 toolchain based on STM32 HAL libraries.
I know that STM32CubeMx supports freeRTOS packages. How can I integrate freeRTOS in my automatic code generation?Hi, I’m trying to integrate the Real Time Operating System capability for the Stm32f407vg discovery board Target by automatic generation code of a simulink model.
I found "ST Discovery Board Support from Embedded Coder" that is based on STM32 Standard Peripheral Libraries, but I use the Simulink+STM32CubeMx+Keil5 toolchain based on STM32 HAL libraries.
I know that STM32CubeMx supports freeRTOS packages. How can I integrate freeRTOS in my automatic code generation? Hi, I’m trying to integrate the Real Time Operating System capability for the Stm32f407vg discovery board Target by automatic generation code of a simulink model.
I found "ST Discovery Board Support from Embedded Coder" that is based on STM32 Standard Peripheral Libraries, but I use the Simulink+STM32CubeMx+Keil5 toolchain based on STM32 HAL libraries.
I know that STM32CubeMx supports freeRTOS packages. How can I integrate freeRTOS in my automatic code generation? st, stm32cubemx, keil MATLAB Answers — New Questions
how to solve XCP connection error
when I enter connect(xcpch), an error "Device not detected." is appearing.
Does anyone know rootcause and how to solve it?
thank you in advance,when I enter connect(xcpch), an error "Device not detected." is appearing.
Does anyone know rootcause and how to solve it?
thank you in advance, when I enter connect(xcpch), an error "Device not detected." is appearing.
Does anyone know rootcause and how to solve it?
thank you in advance, xcp, matlab, simulink MATLAB Answers — New Questions
How I Can Find The HumanActivityData data set contains over 380000 observations of five different physical human activities? from Brian Hu
Load Raw Sensor Data
The HumanActivityData data set contains over 380000 observations of five different physical human activities captured at a frequency of 10 Hz. Each observation includes x, y, and z acceleration data measured by a smartphone accelerometer sensor.Load Raw Sensor Data
The HumanActivityData data set contains over 380000 observations of five different physical human activities captured at a frequency of 10 Hz. Each observation includes x, y, and z acceleration data measured by a smartphone accelerometer sensor. Load Raw Sensor Data
The HumanActivityData data set contains over 380000 observations of five different physical human activities captured at a frequency of 10 Hz. Each observation includes x, y, and z acceleration data measured by a smartphone accelerometer sensor. the humanactivitydata MATLAB Answers — New Questions
Where to find the generated simscape code
Hi does anyone know where to find the generated simscape code? I simply built a dummy model down below and then used simulink coder to generate the c code. I already know that the Simulink Coder software generates code from the Simscape blocks separately from the Simulink blocks in my model, but where does this file store? and which file contains the c code of the simcape blocks?Hi does anyone know where to find the generated simscape code? I simply built a dummy model down below and then used simulink coder to generate the c code. I already know that the Simulink Coder software generates code from the Simscape blocks separately from the Simulink blocks in my model, but where does this file store? and which file contains the c code of the simcape blocks? Hi does anyone know where to find the generated simscape code? I simply built a dummy model down below and then used simulink coder to generate the c code. I already know that the Simulink Coder software generates code from the Simscape blocks separately from the Simulink blocks in my model, but where does this file store? and which file contains the c code of the simcape blocks? simscape, code generation MATLAB Answers — New Questions
Automatically select the right number of bins (or combine the bins) for the expected frequencies in crosstab, in order to guarantee at least 5 elements per bin
I have two observed datasets, "x" and "y", that I want to compare the observed frequencies in bins of "x" and "y" against the other, through crosstab. To do so, I first need to place the elements of "x" and "y" into bins, by using the histcounts function. The resulting binned arrays, "cx" and "cy", are then compared to each other with a chi-square test, perfomed by crosstab. The chi-square test of independence is performed to determine if there is a significant association between the frequencies of "x" and "y" across the bins.
However, the chi-square test "is not valid for small samples, and if some of the counts (in the expected frequency) are less than five, you may need to combine some bins in the tails.". In the following example, several bins of the observed frequencies "cx" and "cy" have zero elements, and I do not know if they affect the expected frequencies calculated within/by crosstab.
Therefore, is there a way in crosstab to automatically select the right number of bins for the expected frequencies, or to combine them if some are empty, in order to guarantee at least 5 elements per bin?
rng default; % for reproducibility
a = 0;
b = 100;
nb = 50;
% Create two log-normal distributed random datasets, "x" and "y’
% (but we can use any randomly distributed data)
x = (b-a).*round(lognrnd(1,1,1000,1)) + a;
y = (b-a).*round(lognrnd(0.88,1.1,1000,1)) + a;
% Counts/frequency of "x" and "y"
cx = histcounts(x,’NumBins’,nb);
cy = histcounts(y,’NumBins’,nb);
[~,chi2,p] = crosstab(cx,cy)I have two observed datasets, "x" and "y", that I want to compare the observed frequencies in bins of "x" and "y" against the other, through crosstab. To do so, I first need to place the elements of "x" and "y" into bins, by using the histcounts function. The resulting binned arrays, "cx" and "cy", are then compared to each other with a chi-square test, perfomed by crosstab. The chi-square test of independence is performed to determine if there is a significant association between the frequencies of "x" and "y" across the bins.
However, the chi-square test "is not valid for small samples, and if some of the counts (in the expected frequency) are less than five, you may need to combine some bins in the tails.". In the following example, several bins of the observed frequencies "cx" and "cy" have zero elements, and I do not know if they affect the expected frequencies calculated within/by crosstab.
Therefore, is there a way in crosstab to automatically select the right number of bins for the expected frequencies, or to combine them if some are empty, in order to guarantee at least 5 elements per bin?
rng default; % for reproducibility
a = 0;
b = 100;
nb = 50;
% Create two log-normal distributed random datasets, "x" and "y’
% (but we can use any randomly distributed data)
x = (b-a).*round(lognrnd(1,1,1000,1)) + a;
y = (b-a).*round(lognrnd(0.88,1.1,1000,1)) + a;
% Counts/frequency of "x" and "y"
cx = histcounts(x,’NumBins’,nb);
cy = histcounts(y,’NumBins’,nb);
[~,chi2,p] = crosstab(cx,cy) I have two observed datasets, "x" and "y", that I want to compare the observed frequencies in bins of "x" and "y" against the other, through crosstab. To do so, I first need to place the elements of "x" and "y" into bins, by using the histcounts function. The resulting binned arrays, "cx" and "cy", are then compared to each other with a chi-square test, perfomed by crosstab. The chi-square test of independence is performed to determine if there is a significant association between the frequencies of "x" and "y" across the bins.
However, the chi-square test "is not valid for small samples, and if some of the counts (in the expected frequency) are less than five, you may need to combine some bins in the tails.". In the following example, several bins of the observed frequencies "cx" and "cy" have zero elements, and I do not know if they affect the expected frequencies calculated within/by crosstab.
Therefore, is there a way in crosstab to automatically select the right number of bins for the expected frequencies, or to combine them if some are empty, in order to guarantee at least 5 elements per bin?
rng default; % for reproducibility
a = 0;
b = 100;
nb = 50;
% Create two log-normal distributed random datasets, "x" and "y’
% (but we can use any randomly distributed data)
x = (b-a).*round(lognrnd(1,1,1000,1)) + a;
y = (b-a).*round(lognrnd(0.88,1.1,1000,1)) + a;
% Counts/frequency of "x" and "y"
cx = histcounts(x,’NumBins’,nb);
cy = histcounts(y,’NumBins’,nb);
[~,chi2,p] = crosstab(cx,cy) crosstab, binning, binned, array, histcounts MATLAB Answers — New Questions
rtwbuild doesn’t generate modelsources.txt in MATLAB 2023
I have used rtwbuild in MATLAB 2020a and it generated modelsources.txt.
MATLAB 2023a doesn’t generate this file. Please help me to solve it.I have used rtwbuild in MATLAB 2020a and it generated modelsources.txt.
MATLAB 2023a doesn’t generate this file. Please help me to solve it. I have used rtwbuild in MATLAB 2020a and it generated modelsources.txt.
MATLAB 2023a doesn’t generate this file. Please help me to solve it. 2023a, simulink MATLAB Answers — New Questions
RMS Analysis on BIN File in Simulink
I am trying to import a BIN file into Simulink and analyze it for RMS. I currently have the sine wave, RMS, and scope blocks, and I can generate a sample sine wave, but I have no way of importing my BIN files. They are large, and I attempted using the Binary File Reader block, and while it started creating a sine wave, it was taking too long to run. How do I make this process more efficient?I am trying to import a BIN file into Simulink and analyze it for RMS. I currently have the sine wave, RMS, and scope blocks, and I can generate a sample sine wave, but I have no way of importing my BIN files. They are large, and I attempted using the Binary File Reader block, and while it started creating a sine wave, it was taking too long to run. How do I make this process more efficient? I am trying to import a BIN file into Simulink and analyze it for RMS. I currently have the sine wave, RMS, and scope blocks, and I can generate a sample sine wave, but I have no way of importing my BIN files. They are large, and I attempted using the Binary File Reader block, and while it started creating a sine wave, it was taking too long to run. How do I make this process more efficient? simulink, binary, statistics MATLAB Answers — New Questions
How to update a function with output from another function?
I am trying to solve for heat transfer coefficients so that I can use them to calculate gas and tank wall temperatures. Currently, I am using constant heat transfer coefficients to enable the calculation of the desired temperatures with ode45.
% Convective heat transfer coefficients
h_in = 25; % Convective heat transfer coefficient inside the tank (W/(m^2·K))
h_out = 6; % Convective heat transfer coefficient outside the tank (W/(m^2·K))
% Solve the coupled ODEs and PDE
[t, y] = ode45(@(t, y) odes(t, y, R, C_p_gas, k_liner, k_CFRP, rho_liner, rho_CFRP, C_p_liner, C_p_CFRP, h_in, h_out, T_ambient, A_in, A_out, dx_liner, dx_CFRP, N_liner, N_CFRP, V, mdot_out), tspan, initial_conditions);
% Extract time histories for inside and outside wall temperatures
T_wall_liner_interface = y(:,3); % Inside wall temperature (first point of the liner)
T_wall_CFRP_interface = y(:,end); % Outside wall temperature (last point of the CFRP layer)
What I would like to do is to use the output temperatures from the ode45 to solve for h_in and h_out, which will in turn be used by ode45 to solve for new temperatures. The h_in and h_out calculations look like this:
function [h_in, h_out]=heat_transfer_coefficients
Di = 0.230; % Internal diameter in meters
Do = 0.279; % External diameter in meters
T_gf = 266.17; %(K) – Type III hydrogen gas T at film temp
rho_gf = 39.16; %(kg/m^3) – Type III hydrogen gas density @ T_gf
Cp_gf = 0.01514*((T_gf/100)^4.789)+1002;
mu_gf = (-4.127*10^-7)*((T_gf/100)^2)+((7.258*10^-6)*(T_gf/100))+(4.094*10^-7);
lambda_gf = ((-3.77*10^-4)*(T_gf/100)^2)+((1.004*10^-2)*(T_gf/100))-(4.776*10^-4);
beta_gf = 1/T_gf; %volumetric thermal expansion coefficient
g = 9.81; %gravitational acceleration (m/s^2)
Rai = (rho_gf^2*(Di^3)*beta_gf*g*(T_wall_liner_interface-T_gas)*Cp_gf)/(mu_gf*lambda_gf); %Rayleigh number at inner wall
if Rai < 10^8
Nu_i = 1.15*Rai.^0.22;
else
Nu_i = 0.14*Rai.^0.333;
end
ki = 168.9e3; %thermal conductivity inside tank at T_g, Type III (W/m*K)
h_in = (Nu_i*ki)/Di;
T_ambf = 279.43; %(K) – Type III
rho_ambf = 1.263; %(kg/m^3) – density @ T_ambf
c_wind = 0; %(m/s) – cross wind velocity
Cp_ambf = 0.01514*((T_ambf/100)^4.789)+1002;
mu_ambf = (-4.127*10^-7)*((T_ambf/100)^2)+((7.258*10^-6)*(T_ambf/100))+(4.094*10^-7);
lambda_ambf = ((-3.77*10^-4)*(T_ambf/100)^2)+((1.004*10^-2)*(T_ambf/100))-(4.776*10^-4);
beta_ambf = 1/T_ambf; %volumetric thermal expansion coefficient
Re_Do = (rho_ambf*c_wind*Do)/(mu_ambf);
Pr_ambf = (mu_ambf*Cp_ambf)/lambda_ambf;
if Re_Do == 0
Nu_cylforced = 0;
Nu_sphforced = 0;
else
Nu_cylforced = 0.3+((0.62*(Re_Do^0.5)*(Pr_ambf^(1/3)))/(1+(0.4/((Pr_ambf))^(2/3)))^(1/4))…
*(1+(Re_Do/282000)^5/8)^4/5;
Nu_sphforced = 2 + ((Re_Do/4)+((3*10^-4)*Re_Do^1.6))^0.5;
end
Rao = (rho_ambf^2*(Do^3)*beta_ambf*g*(T_amb-T_wall_CFRP_interface)*Cp_ambf)/(mu_ambf*lambda_ambf); %Rayleigh number at inner wall
Nu_oforced = ((Nu_cylforced*0.72)+(Nu_sphforced*0.24))/(0.72+0.24);
Nu_ofree = (0.6+((0.387*(Rao.^(1/6)))/(1+(0.559/Pr_ambf)^(9/16)).^(8/27))).^2;
Nu_o = ((Nu_ofree.^4)+(Nu_oforced^4)).^0.25;
ko = 24.84e3; %thermal conductivity outside tank at T_wo, Type III (W/m*K)
h_out = (Nu_o*ko)/Do;
end
As can be seen in the above code, the h_in and h_out calculations require T_gas, T_wall_liner interface and T_wall_CFRP_interface, which currently are being calculated after h_in and h_out. Can somebody please show me a way I can incorporate the h_in and h_out calculations into the first section of code? For ease of explanation and solving, please feel free to use your own numbers for the constants in the ode45 solver line.I am trying to solve for heat transfer coefficients so that I can use them to calculate gas and tank wall temperatures. Currently, I am using constant heat transfer coefficients to enable the calculation of the desired temperatures with ode45.
% Convective heat transfer coefficients
h_in = 25; % Convective heat transfer coefficient inside the tank (W/(m^2·K))
h_out = 6; % Convective heat transfer coefficient outside the tank (W/(m^2·K))
% Solve the coupled ODEs and PDE
[t, y] = ode45(@(t, y) odes(t, y, R, C_p_gas, k_liner, k_CFRP, rho_liner, rho_CFRP, C_p_liner, C_p_CFRP, h_in, h_out, T_ambient, A_in, A_out, dx_liner, dx_CFRP, N_liner, N_CFRP, V, mdot_out), tspan, initial_conditions);
% Extract time histories for inside and outside wall temperatures
T_wall_liner_interface = y(:,3); % Inside wall temperature (first point of the liner)
T_wall_CFRP_interface = y(:,end); % Outside wall temperature (last point of the CFRP layer)
What I would like to do is to use the output temperatures from the ode45 to solve for h_in and h_out, which will in turn be used by ode45 to solve for new temperatures. The h_in and h_out calculations look like this:
function [h_in, h_out]=heat_transfer_coefficients
Di = 0.230; % Internal diameter in meters
Do = 0.279; % External diameter in meters
T_gf = 266.17; %(K) – Type III hydrogen gas T at film temp
rho_gf = 39.16; %(kg/m^3) – Type III hydrogen gas density @ T_gf
Cp_gf = 0.01514*((T_gf/100)^4.789)+1002;
mu_gf = (-4.127*10^-7)*((T_gf/100)^2)+((7.258*10^-6)*(T_gf/100))+(4.094*10^-7);
lambda_gf = ((-3.77*10^-4)*(T_gf/100)^2)+((1.004*10^-2)*(T_gf/100))-(4.776*10^-4);
beta_gf = 1/T_gf; %volumetric thermal expansion coefficient
g = 9.81; %gravitational acceleration (m/s^2)
Rai = (rho_gf^2*(Di^3)*beta_gf*g*(T_wall_liner_interface-T_gas)*Cp_gf)/(mu_gf*lambda_gf); %Rayleigh number at inner wall
if Rai < 10^8
Nu_i = 1.15*Rai.^0.22;
else
Nu_i = 0.14*Rai.^0.333;
end
ki = 168.9e3; %thermal conductivity inside tank at T_g, Type III (W/m*K)
h_in = (Nu_i*ki)/Di;
T_ambf = 279.43; %(K) – Type III
rho_ambf = 1.263; %(kg/m^3) – density @ T_ambf
c_wind = 0; %(m/s) – cross wind velocity
Cp_ambf = 0.01514*((T_ambf/100)^4.789)+1002;
mu_ambf = (-4.127*10^-7)*((T_ambf/100)^2)+((7.258*10^-6)*(T_ambf/100))+(4.094*10^-7);
lambda_ambf = ((-3.77*10^-4)*(T_ambf/100)^2)+((1.004*10^-2)*(T_ambf/100))-(4.776*10^-4);
beta_ambf = 1/T_ambf; %volumetric thermal expansion coefficient
Re_Do = (rho_ambf*c_wind*Do)/(mu_ambf);
Pr_ambf = (mu_ambf*Cp_ambf)/lambda_ambf;
if Re_Do == 0
Nu_cylforced = 0;
Nu_sphforced = 0;
else
Nu_cylforced = 0.3+((0.62*(Re_Do^0.5)*(Pr_ambf^(1/3)))/(1+(0.4/((Pr_ambf))^(2/3)))^(1/4))…
*(1+(Re_Do/282000)^5/8)^4/5;
Nu_sphforced = 2 + ((Re_Do/4)+((3*10^-4)*Re_Do^1.6))^0.5;
end
Rao = (rho_ambf^2*(Do^3)*beta_ambf*g*(T_amb-T_wall_CFRP_interface)*Cp_ambf)/(mu_ambf*lambda_ambf); %Rayleigh number at inner wall
Nu_oforced = ((Nu_cylforced*0.72)+(Nu_sphforced*0.24))/(0.72+0.24);
Nu_ofree = (0.6+((0.387*(Rao.^(1/6)))/(1+(0.559/Pr_ambf)^(9/16)).^(8/27))).^2;
Nu_o = ((Nu_ofree.^4)+(Nu_oforced^4)).^0.25;
ko = 24.84e3; %thermal conductivity outside tank at T_wo, Type III (W/m*K)
h_out = (Nu_o*ko)/Do;
end
As can be seen in the above code, the h_in and h_out calculations require T_gas, T_wall_liner interface and T_wall_CFRP_interface, which currently are being calculated after h_in and h_out. Can somebody please show me a way I can incorporate the h_in and h_out calculations into the first section of code? For ease of explanation and solving, please feel free to use your own numbers for the constants in the ode45 solver line. I am trying to solve for heat transfer coefficients so that I can use them to calculate gas and tank wall temperatures. Currently, I am using constant heat transfer coefficients to enable the calculation of the desired temperatures with ode45.
% Convective heat transfer coefficients
h_in = 25; % Convective heat transfer coefficient inside the tank (W/(m^2·K))
h_out = 6; % Convective heat transfer coefficient outside the tank (W/(m^2·K))
% Solve the coupled ODEs and PDE
[t, y] = ode45(@(t, y) odes(t, y, R, C_p_gas, k_liner, k_CFRP, rho_liner, rho_CFRP, C_p_liner, C_p_CFRP, h_in, h_out, T_ambient, A_in, A_out, dx_liner, dx_CFRP, N_liner, N_CFRP, V, mdot_out), tspan, initial_conditions);
% Extract time histories for inside and outside wall temperatures
T_wall_liner_interface = y(:,3); % Inside wall temperature (first point of the liner)
T_wall_CFRP_interface = y(:,end); % Outside wall temperature (last point of the CFRP layer)
What I would like to do is to use the output temperatures from the ode45 to solve for h_in and h_out, which will in turn be used by ode45 to solve for new temperatures. The h_in and h_out calculations look like this:
function [h_in, h_out]=heat_transfer_coefficients
Di = 0.230; % Internal diameter in meters
Do = 0.279; % External diameter in meters
T_gf = 266.17; %(K) – Type III hydrogen gas T at film temp
rho_gf = 39.16; %(kg/m^3) – Type III hydrogen gas density @ T_gf
Cp_gf = 0.01514*((T_gf/100)^4.789)+1002;
mu_gf = (-4.127*10^-7)*((T_gf/100)^2)+((7.258*10^-6)*(T_gf/100))+(4.094*10^-7);
lambda_gf = ((-3.77*10^-4)*(T_gf/100)^2)+((1.004*10^-2)*(T_gf/100))-(4.776*10^-4);
beta_gf = 1/T_gf; %volumetric thermal expansion coefficient
g = 9.81; %gravitational acceleration (m/s^2)
Rai = (rho_gf^2*(Di^3)*beta_gf*g*(T_wall_liner_interface-T_gas)*Cp_gf)/(mu_gf*lambda_gf); %Rayleigh number at inner wall
if Rai < 10^8
Nu_i = 1.15*Rai.^0.22;
else
Nu_i = 0.14*Rai.^0.333;
end
ki = 168.9e3; %thermal conductivity inside tank at T_g, Type III (W/m*K)
h_in = (Nu_i*ki)/Di;
T_ambf = 279.43; %(K) – Type III
rho_ambf = 1.263; %(kg/m^3) – density @ T_ambf
c_wind = 0; %(m/s) – cross wind velocity
Cp_ambf = 0.01514*((T_ambf/100)^4.789)+1002;
mu_ambf = (-4.127*10^-7)*((T_ambf/100)^2)+((7.258*10^-6)*(T_ambf/100))+(4.094*10^-7);
lambda_ambf = ((-3.77*10^-4)*(T_ambf/100)^2)+((1.004*10^-2)*(T_ambf/100))-(4.776*10^-4);
beta_ambf = 1/T_ambf; %volumetric thermal expansion coefficient
Re_Do = (rho_ambf*c_wind*Do)/(mu_ambf);
Pr_ambf = (mu_ambf*Cp_ambf)/lambda_ambf;
if Re_Do == 0
Nu_cylforced = 0;
Nu_sphforced = 0;
else
Nu_cylforced = 0.3+((0.62*(Re_Do^0.5)*(Pr_ambf^(1/3)))/(1+(0.4/((Pr_ambf))^(2/3)))^(1/4))…
*(1+(Re_Do/282000)^5/8)^4/5;
Nu_sphforced = 2 + ((Re_Do/4)+((3*10^-4)*Re_Do^1.6))^0.5;
end
Rao = (rho_ambf^2*(Do^3)*beta_ambf*g*(T_amb-T_wall_CFRP_interface)*Cp_ambf)/(mu_ambf*lambda_ambf); %Rayleigh number at inner wall
Nu_oforced = ((Nu_cylforced*0.72)+(Nu_sphforced*0.24))/(0.72+0.24);
Nu_ofree = (0.6+((0.387*(Rao.^(1/6)))/(1+(0.559/Pr_ambf)^(9/16)).^(8/27))).^2;
Nu_o = ((Nu_ofree.^4)+(Nu_oforced^4)).^0.25;
ko = 24.84e3; %thermal conductivity outside tank at T_wo, Type III (W/m*K)
h_out = (Nu_o*ko)/Do;
end
As can be seen in the above code, the h_in and h_out calculations require T_gas, T_wall_liner interface and T_wall_CFRP_interface, which currently are being calculated after h_in and h_out. Can somebody please show me a way I can incorporate the h_in and h_out calculations into the first section of code? For ease of explanation and solving, please feel free to use your own numbers for the constants in the ode45 solver line. function MATLAB Answers — New Questions
Unable to recognise function from called script
I created this function in a scipted named "lab1_script.m":
t = [1, 2, 3, 4]
function y = lab1_function(t, c)
y = c*t.^2;
end
But when I try to call the script in a new script as follows:
lab1_script;
y = lab1_function(t,0.1)
The error message: unrecognisable function or variable ‘lab1_function’ appears. And I know that the function works, because when I call it within the same script it is fine. It is just trying to call it into a different script that I am having trouble with.
I am confused, what am I doing wrong? Should I be calling the script a different way for the function to be recognised?
Thanks in advance! :)I created this function in a scipted named "lab1_script.m":
t = [1, 2, 3, 4]
function y = lab1_function(t, c)
y = c*t.^2;
end
But when I try to call the script in a new script as follows:
lab1_script;
y = lab1_function(t,0.1)
The error message: unrecognisable function or variable ‘lab1_function’ appears. And I know that the function works, because when I call it within the same script it is fine. It is just trying to call it into a different script that I am having trouble with.
I am confused, what am I doing wrong? Should I be calling the script a different way for the function to be recognised?
Thanks in advance! 🙂 I created this function in a scipted named "lab1_script.m":
t = [1, 2, 3, 4]
function y = lab1_function(t, c)
y = c*t.^2;
end
But when I try to call the script in a new script as follows:
lab1_script;
y = lab1_function(t,0.1)
The error message: unrecognisable function or variable ‘lab1_function’ appears. And I know that the function works, because when I call it within the same script it is fine. It is just trying to call it into a different script that I am having trouble with.
I am confused, what am I doing wrong? Should I be calling the script a different way for the function to be recognised?
Thanks in advance! 🙂 function, calling script MATLAB Answers — New Questions
Detecting residential areas in maps
Hello, trying to understand which strategy works best here.
I am using the mapping toolbox for a research project, which includes the calculation of the average distance/time for traveling from a number of polygonal ROIs (e.g. area of cities) to a given destination. This will in turn provide a measurement for the average cost that residents in the ROI have to endure in order to travel to the destination.
My script goes:
Consider one boundary polygon and geolocate it.
Build a grid of equally spaced geopoints within the polygon.
For each point in step 2, query the OSRM routing engine to the destination and store the response.
Average the distances/times.
I don’t like the current version of step 4, as the algorithm is applying the same weight to points in downtown and in the deep countryside. I would like to achieve a weighted average, where the weights represent a measure of the probability that someone lives nearby a given query point. This basically means detecting residential areas.
I’m not sure how to tackle this, as I’ve never worked with image processing (I’m assuming that’s the way, but I could be wrong). I thought about using geobasemap in ‘streets-light’ mode, and process the amount of pure white color in the picture, which would represent a measure of how much public road exists in a given portion of my ROI. The more roads are present, the less likely it is that we’re in the deep countryside.
I’m pretty sure there are more appropriate workarounds. Has anyone encountered a similar problem? Thank you very much.Hello, trying to understand which strategy works best here.
I am using the mapping toolbox for a research project, which includes the calculation of the average distance/time for traveling from a number of polygonal ROIs (e.g. area of cities) to a given destination. This will in turn provide a measurement for the average cost that residents in the ROI have to endure in order to travel to the destination.
My script goes:
Consider one boundary polygon and geolocate it.
Build a grid of equally spaced geopoints within the polygon.
For each point in step 2, query the OSRM routing engine to the destination and store the response.
Average the distances/times.
I don’t like the current version of step 4, as the algorithm is applying the same weight to points in downtown and in the deep countryside. I would like to achieve a weighted average, where the weights represent a measure of the probability that someone lives nearby a given query point. This basically means detecting residential areas.
I’m not sure how to tackle this, as I’ve never worked with image processing (I’m assuming that’s the way, but I could be wrong). I thought about using geobasemap in ‘streets-light’ mode, and process the amount of pure white color in the picture, which would represent a measure of how much public road exists in a given portion of my ROI. The more roads are present, the less likely it is that we’re in the deep countryside.
I’m pretty sure there are more appropriate workarounds. Has anyone encountered a similar problem? Thank you very much. Hello, trying to understand which strategy works best here.
I am using the mapping toolbox for a research project, which includes the calculation of the average distance/time for traveling from a number of polygonal ROIs (e.g. area of cities) to a given destination. This will in turn provide a measurement for the average cost that residents in the ROI have to endure in order to travel to the destination.
My script goes:
Consider one boundary polygon and geolocate it.
Build a grid of equally spaced geopoints within the polygon.
For each point in step 2, query the OSRM routing engine to the destination and store the response.
Average the distances/times.
I don’t like the current version of step 4, as the algorithm is applying the same weight to points in downtown and in the deep countryside. I would like to achieve a weighted average, where the weights represent a measure of the probability that someone lives nearby a given query point. This basically means detecting residential areas.
I’m not sure how to tackle this, as I’ve never worked with image processing (I’m assuming that’s the way, but I could be wrong). I thought about using geobasemap in ‘streets-light’ mode, and process the amount of pure white color in the picture, which would represent a measure of how much public road exists in a given portion of my ROI. The more roads are present, the less likely it is that we’re in the deep countryside.
I’m pretty sure there are more appropriate workarounds. Has anyone encountered a similar problem? Thank you very much. image processing, matlab, figure, image analysis, geobasemap MATLAB Answers — New Questions
From and Goto block connected block list?
how to find connected Corresponding From blocks list in Goto block? (Using mscript)
Similarly for From Block?how to find connected Corresponding From blocks list in Goto block? (Using mscript)
Similarly for From Block? how to find connected Corresponding From blocks list in Goto block? (Using mscript)
Similarly for From Block? from, goto block, mscript MATLAB Answers — New Questions
Run a python exe from within a Matlab exe with Administrator permissions
I would like to run a python.exe from within a Matlab.exe file with administrator permissions.Unfortunately, the python.exe does not have the necessary permissions to write out a file. I have tried executing it directly from command prompt as administrator and it works perfectly. The process fails when I try executing it within the matlab exe. The workflow is as follows:
The python.exe receives two inputs as arguments i) filename – which is a path to a particular file ii) value
ML_correction.exe –filename "C:/…/../xx.txt" –corrected_val "-185.7"
The python exe computes a certain value and writes out a .mat file
2. The above command to call the python exe is executed within a Matlab exe as follows:
python_path="C:/…/../xx.txt";
val=-185.7;
cmd_command=[‘….ML_correction.exe –filename "’ python_path ‘" –corrected_val "’ num2str(val) ‘"’];
[status,cmdout] = system(cmd_command);
I have read the suggestions from @Jan and @Guillaume : https://de.mathworks.com/matlabcentral/answers/398700-run-external-software-from-matlab-using-system-with-admin-rights
I tried to pass my arguments using ShellExecute from Microsoft documentation but I am definitely doing it wrong. I have tried the following:
cmd_command=[‘….ML_correction.exe –filename "’ python_path ‘" –corrected_val "’ num2str(val) ‘"’];
exepath=string(cmd_command);
uac = actxserver(‘Shell.Application’);
uac.ShellExecute(exepath, "ELEV", "", "runas", 1);
Thank You!
I am using Windows 10 and Matlab2017bI would like to run a python.exe from within a Matlab.exe file with administrator permissions.Unfortunately, the python.exe does not have the necessary permissions to write out a file. I have tried executing it directly from command prompt as administrator and it works perfectly. The process fails when I try executing it within the matlab exe. The workflow is as follows:
The python.exe receives two inputs as arguments i) filename – which is a path to a particular file ii) value
ML_correction.exe –filename "C:/…/../xx.txt" –corrected_val "-185.7"
The python exe computes a certain value and writes out a .mat file
2. The above command to call the python exe is executed within a Matlab exe as follows:
python_path="C:/…/../xx.txt";
val=-185.7;
cmd_command=[‘….ML_correction.exe –filename "’ python_path ‘" –corrected_val "’ num2str(val) ‘"’];
[status,cmdout] = system(cmd_command);
I have read the suggestions from @Jan and @Guillaume : https://de.mathworks.com/matlabcentral/answers/398700-run-external-software-from-matlab-using-system-with-admin-rights
I tried to pass my arguments using ShellExecute from Microsoft documentation but I am definitely doing it wrong. I have tried the following:
cmd_command=[‘….ML_correction.exe –filename "’ python_path ‘" –corrected_val "’ num2str(val) ‘"’];
exepath=string(cmd_command);
uac = actxserver(‘Shell.Application’);
uac.ShellExecute(exepath, "ELEV", "", "runas", 1);
Thank You!
I am using Windows 10 and Matlab2017b I would like to run a python.exe from within a Matlab.exe file with administrator permissions.Unfortunately, the python.exe does not have the necessary permissions to write out a file. I have tried executing it directly from command prompt as administrator and it works perfectly. The process fails when I try executing it within the matlab exe. The workflow is as follows:
The python.exe receives two inputs as arguments i) filename – which is a path to a particular file ii) value
ML_correction.exe –filename "C:/…/../xx.txt" –corrected_val "-185.7"
The python exe computes a certain value and writes out a .mat file
2. The above command to call the python exe is executed within a Matlab exe as follows:
python_path="C:/…/../xx.txt";
val=-185.7;
cmd_command=[‘….ML_correction.exe –filename "’ python_path ‘" –corrected_val "’ num2str(val) ‘"’];
[status,cmdout] = system(cmd_command);
I have read the suggestions from @Jan and @Guillaume : https://de.mathworks.com/matlabcentral/answers/398700-run-external-software-from-matlab-using-system-with-admin-rights
I tried to pass my arguments using ShellExecute from Microsoft documentation but I am definitely doing it wrong. I have tried the following:
cmd_command=[‘….ML_correction.exe –filename "’ python_path ‘" –corrected_val "’ num2str(val) ‘"’];
exepath=string(cmd_command);
uac = actxserver(‘Shell.Application’);
uac.ShellExecute(exepath, "ELEV", "", "runas", 1);
Thank You!
I am using Windows 10 and Matlab2017b system, python exe, matlab exe MATLAB Answers — New Questions
Trouble with an array
Hello,
I have some trouble with an array. I try to set the values for a 3D array (nx x ny x nz) that all inner nodes are set to a defined value, all surface nodes (except the edge nodes) are set to a defined value too. It’s like a small cube in a greater cube.
Here is the code I used:
clc;
clear all;
clf;
format short g
fontSize = 18;
% Domaine
L=0.1;
B=0.1;
H=0.1;
nx=5;
ny=5;
nz=5;
dx=L/(nx-1);
dy=B/(ny-1);
dz=H/(nz-1);
% Nodes
Tn=zeros(nx,ny,nz);
x=linspace(0,L,nx);
y=linspace(0,H,ny);
z=linspace(0,B,nz);
[X,Y,Z]=meshgrid(x,y,z);
K=zeros(nx,ny,nz);
K([1 end],:,:)=alpha;
K(:,[1 end],:)=alpha;
K(:,:,[1 end])=alpha;
% inner nodes
T=zeros(nx,ny,nz);
T(:,:,:)=700;
t=0;
% surrounding surfaces
Tu=600; % bottom
To=900; % top
Tl=400; % left
Tr=800; % rigth
Tv=300; % front
Th=300; % back
% side surfaces
Tn(1,2:nx-2,2:nz-2)=Tv; % front
Tn(ny,2:nx-2,2:nz-2)=Th; % back
Tn(2:ny-2,2:nx-2,1)=Tu; % bottom
Tn(2:ny-2,2:nx-2,nz)=To; % top
Tn(2:ny-2,1,2:nz-2)=Tl; % left
Tn(2:ny-2,nx,2:nz-2)=Tr; % rigth
% merge inner nodes
Tn(2:ny-2,2:nx-2,2:nz-2) = T(2:ny-2,2:nx-2,2:nz-2);
f = figure(1);
f.Position(3:4) = [1080 840];
%XY
subplot(2,2,1)
slice(X,Y,Z,Tn,[],[],[0,H],’cubic’);
set(gca,’FontSize’,fontSize)
colormap(jet)
xlabel(‘X -Axis’,’FontSize’, fontSize)
ylabel(‘Y -Axis’,’FontSize’, fontSize)
zlabel(‘Z -Axis’,’FontSize’, fontSize)
axis([0 L 0 B 0 H]);
view(30,30);
% XZ
subplot(2,2,2)
slice(X,Y,Z,Tn,[],[0,B],[],’cubic’);
set(gca,’FontSize’,fontSize)
colormap(jet)
%set ( gca, ‘ydir’, ‘reverse’ )
xlabel(‘X -Axis’,’FontSize’, fontSize)
ylabel(‘Y -Axis’,’FontSize’, fontSize)
zlabel(‘Z -Axis’,’FontSize’, fontSize)
axis([0 L 0 B 0 H]);
view(30,30);
% YZ
subplot(2,2,3)
slice(X,Y,Z,Tn,[0,L],[],[],’cubic’);
set(gca,’FontSize’,fontSize)
colormap(jet)
%set ( gca, ‘ydir’, ‘reverse’ )
xlabel(‘X -Axis’,’FontSize’, fontSize)
ylabel(‘Y -Axis’,’FontSize’, fontSize)
zlabel(‘Z -Axis’,’FontSize’, fontSize)
axis([0 L 0 B 0 H]);
view(30,30);
% 3D
subplot(2,2,4)
slice(X,Y,Z,Tn,[0,L/2],[B/2,B],[0],’linear’);
set(gca,’FontSize’,fontSize)
set(gca,’YDir’,’normal’)
colormap(jet)
set ( gca, ‘xdir’, ‘reverse’ )
set ( gca, ‘ydir’, ‘reverse’ )
xlabel(‘X -Axis’,’FontSize’, fontSize)
ylabel(‘Y -Axis’,’FontSize’, fontSize)
zlabel(‘Z -Axis’,’FontSize’, fontSize)
axis([0 L 0 B 0 H])
view(-150,30);
hold on
%shading(gca,’interp’)
p = get(subplot(2,2,4),’Position’);
cb=colorbar(‘Position’, [0.93 0.25 0.025 0.6]);
set(cb,’FontSize’,fontSize);
caxis([0, 900]);
The result I achieve is this:
I marked the false areas with a red sign. I indexed from 2:nx-1 and so on, but it’s not working.
The result should look like this:
I don’t know where the error is. Maybe someone has a clue how to fix this.
Greetings
SteffenHello,
I have some trouble with an array. I try to set the values for a 3D array (nx x ny x nz) that all inner nodes are set to a defined value, all surface nodes (except the edge nodes) are set to a defined value too. It’s like a small cube in a greater cube.
Here is the code I used:
clc;
clear all;
clf;
format short g
fontSize = 18;
% Domaine
L=0.1;
B=0.1;
H=0.1;
nx=5;
ny=5;
nz=5;
dx=L/(nx-1);
dy=B/(ny-1);
dz=H/(nz-1);
% Nodes
Tn=zeros(nx,ny,nz);
x=linspace(0,L,nx);
y=linspace(0,H,ny);
z=linspace(0,B,nz);
[X,Y,Z]=meshgrid(x,y,z);
K=zeros(nx,ny,nz);
K([1 end],:,:)=alpha;
K(:,[1 end],:)=alpha;
K(:,:,[1 end])=alpha;
% inner nodes
T=zeros(nx,ny,nz);
T(:,:,:)=700;
t=0;
% surrounding surfaces
Tu=600; % bottom
To=900; % top
Tl=400; % left
Tr=800; % rigth
Tv=300; % front
Th=300; % back
% side surfaces
Tn(1,2:nx-2,2:nz-2)=Tv; % front
Tn(ny,2:nx-2,2:nz-2)=Th; % back
Tn(2:ny-2,2:nx-2,1)=Tu; % bottom
Tn(2:ny-2,2:nx-2,nz)=To; % top
Tn(2:ny-2,1,2:nz-2)=Tl; % left
Tn(2:ny-2,nx,2:nz-2)=Tr; % rigth
% merge inner nodes
Tn(2:ny-2,2:nx-2,2:nz-2) = T(2:ny-2,2:nx-2,2:nz-2);
f = figure(1);
f.Position(3:4) = [1080 840];
%XY
subplot(2,2,1)
slice(X,Y,Z,Tn,[],[],[0,H],’cubic’);
set(gca,’FontSize’,fontSize)
colormap(jet)
xlabel(‘X -Axis’,’FontSize’, fontSize)
ylabel(‘Y -Axis’,’FontSize’, fontSize)
zlabel(‘Z -Axis’,’FontSize’, fontSize)
axis([0 L 0 B 0 H]);
view(30,30);
% XZ
subplot(2,2,2)
slice(X,Y,Z,Tn,[],[0,B],[],’cubic’);
set(gca,’FontSize’,fontSize)
colormap(jet)
%set ( gca, ‘ydir’, ‘reverse’ )
xlabel(‘X -Axis’,’FontSize’, fontSize)
ylabel(‘Y -Axis’,’FontSize’, fontSize)
zlabel(‘Z -Axis’,’FontSize’, fontSize)
axis([0 L 0 B 0 H]);
view(30,30);
% YZ
subplot(2,2,3)
slice(X,Y,Z,Tn,[0,L],[],[],’cubic’);
set(gca,’FontSize’,fontSize)
colormap(jet)
%set ( gca, ‘ydir’, ‘reverse’ )
xlabel(‘X -Axis’,’FontSize’, fontSize)
ylabel(‘Y -Axis’,’FontSize’, fontSize)
zlabel(‘Z -Axis’,’FontSize’, fontSize)
axis([0 L 0 B 0 H]);
view(30,30);
% 3D
subplot(2,2,4)
slice(X,Y,Z,Tn,[0,L/2],[B/2,B],[0],’linear’);
set(gca,’FontSize’,fontSize)
set(gca,’YDir’,’normal’)
colormap(jet)
set ( gca, ‘xdir’, ‘reverse’ )
set ( gca, ‘ydir’, ‘reverse’ )
xlabel(‘X -Axis’,’FontSize’, fontSize)
ylabel(‘Y -Axis’,’FontSize’, fontSize)
zlabel(‘Z -Axis’,’FontSize’, fontSize)
axis([0 L 0 B 0 H])
view(-150,30);
hold on
%shading(gca,’interp’)
p = get(subplot(2,2,4),’Position’);
cb=colorbar(‘Position’, [0.93 0.25 0.025 0.6]);
set(cb,’FontSize’,fontSize);
caxis([0, 900]);
The result I achieve is this:
I marked the false areas with a red sign. I indexed from 2:nx-1 and so on, but it’s not working.
The result should look like this:
I don’t know where the error is. Maybe someone has a clue how to fix this.
Greetings
Steffen Hello,
I have some trouble with an array. I try to set the values for a 3D array (nx x ny x nz) that all inner nodes are set to a defined value, all surface nodes (except the edge nodes) are set to a defined value too. It’s like a small cube in a greater cube.
Here is the code I used:
clc;
clear all;
clf;
format short g
fontSize = 18;
% Domaine
L=0.1;
B=0.1;
H=0.1;
nx=5;
ny=5;
nz=5;
dx=L/(nx-1);
dy=B/(ny-1);
dz=H/(nz-1);
% Nodes
Tn=zeros(nx,ny,nz);
x=linspace(0,L,nx);
y=linspace(0,H,ny);
z=linspace(0,B,nz);
[X,Y,Z]=meshgrid(x,y,z);
K=zeros(nx,ny,nz);
K([1 end],:,:)=alpha;
K(:,[1 end],:)=alpha;
K(:,:,[1 end])=alpha;
% inner nodes
T=zeros(nx,ny,nz);
T(:,:,:)=700;
t=0;
% surrounding surfaces
Tu=600; % bottom
To=900; % top
Tl=400; % left
Tr=800; % rigth
Tv=300; % front
Th=300; % back
% side surfaces
Tn(1,2:nx-2,2:nz-2)=Tv; % front
Tn(ny,2:nx-2,2:nz-2)=Th; % back
Tn(2:ny-2,2:nx-2,1)=Tu; % bottom
Tn(2:ny-2,2:nx-2,nz)=To; % top
Tn(2:ny-2,1,2:nz-2)=Tl; % left
Tn(2:ny-2,nx,2:nz-2)=Tr; % rigth
% merge inner nodes
Tn(2:ny-2,2:nx-2,2:nz-2) = T(2:ny-2,2:nx-2,2:nz-2);
f = figure(1);
f.Position(3:4) = [1080 840];
%XY
subplot(2,2,1)
slice(X,Y,Z,Tn,[],[],[0,H],’cubic’);
set(gca,’FontSize’,fontSize)
colormap(jet)
xlabel(‘X -Axis’,’FontSize’, fontSize)
ylabel(‘Y -Axis’,’FontSize’, fontSize)
zlabel(‘Z -Axis’,’FontSize’, fontSize)
axis([0 L 0 B 0 H]);
view(30,30);
% XZ
subplot(2,2,2)
slice(X,Y,Z,Tn,[],[0,B],[],’cubic’);
set(gca,’FontSize’,fontSize)
colormap(jet)
%set ( gca, ‘ydir’, ‘reverse’ )
xlabel(‘X -Axis’,’FontSize’, fontSize)
ylabel(‘Y -Axis’,’FontSize’, fontSize)
zlabel(‘Z -Axis’,’FontSize’, fontSize)
axis([0 L 0 B 0 H]);
view(30,30);
% YZ
subplot(2,2,3)
slice(X,Y,Z,Tn,[0,L],[],[],’cubic’);
set(gca,’FontSize’,fontSize)
colormap(jet)
%set ( gca, ‘ydir’, ‘reverse’ )
xlabel(‘X -Axis’,’FontSize’, fontSize)
ylabel(‘Y -Axis’,’FontSize’, fontSize)
zlabel(‘Z -Axis’,’FontSize’, fontSize)
axis([0 L 0 B 0 H]);
view(30,30);
% 3D
subplot(2,2,4)
slice(X,Y,Z,Tn,[0,L/2],[B/2,B],[0],’linear’);
set(gca,’FontSize’,fontSize)
set(gca,’YDir’,’normal’)
colormap(jet)
set ( gca, ‘xdir’, ‘reverse’ )
set ( gca, ‘ydir’, ‘reverse’ )
xlabel(‘X -Axis’,’FontSize’, fontSize)
ylabel(‘Y -Axis’,’FontSize’, fontSize)
zlabel(‘Z -Axis’,’FontSize’, fontSize)
axis([0 L 0 B 0 H])
view(-150,30);
hold on
%shading(gca,’interp’)
p = get(subplot(2,2,4),’Position’);
cb=colorbar(‘Position’, [0.93 0.25 0.025 0.6]);
set(cb,’FontSize’,fontSize);
caxis([0, 900]);
The result I achieve is this:
I marked the false areas with a red sign. I indexed from 2:nx-1 and so on, but it’s not working.
The result should look like this:
I don’t know where the error is. Maybe someone has a clue how to fix this.
Greetings
Steffen array, indexing MATLAB Answers — New Questions