Tag Archives: matlab
Matlab crash
Hello!
I have a weird bug when debugging a code in MATLAB.
I start debugging single commands (using F10), and when I want to run the rest of the code by pressing F5 I get a MATLAB system error:
"MATLAB has encountered an internal problem and need to close" containing several options (Sending the information to MathWorks, Attempt to Continue, see more details and ‘End Now’ for closing the program).
I tried sending the error to MathWorks but their answer didn’t help.
In order to continue working I need to end the program and restart it. It doesn’t happen every time, but it happens a lot.
Version details:
MATLAB Version: 7.11.0.584 (R2010b)
Operating System: Microsoft Windows XP Version 5.1 (Build 2600: Service Pack 3)
Java VM Version: Java 1.6.0_17-b04 with Sun Microsystems Inc. Java HotSpot(TM) Client VM mixed mode.
Did someone ever encounter a similar problem?
Thanks!Hello!
I have a weird bug when debugging a code in MATLAB.
I start debugging single commands (using F10), and when I want to run the rest of the code by pressing F5 I get a MATLAB system error:
"MATLAB has encountered an internal problem and need to close" containing several options (Sending the information to MathWorks, Attempt to Continue, see more details and ‘End Now’ for closing the program).
I tried sending the error to MathWorks but their answer didn’t help.
In order to continue working I need to end the program and restart it. It doesn’t happen every time, but it happens a lot.
Version details:
MATLAB Version: 7.11.0.584 (R2010b)
Operating System: Microsoft Windows XP Version 5.1 (Build 2600: Service Pack 3)
Java VM Version: Java 1.6.0_17-b04 with Sun Microsystems Inc. Java HotSpot(TM) Client VM mixed mode.
Did someone ever encounter a similar problem?
Thanks! Hello!
I have a weird bug when debugging a code in MATLAB.
I start debugging single commands (using F10), and when I want to run the rest of the code by pressing F5 I get a MATLAB system error:
"MATLAB has encountered an internal problem and need to close" containing several options (Sending the information to MathWorks, Attempt to Continue, see more details and ‘End Now’ for closing the program).
I tried sending the error to MathWorks but their answer didn’t help.
In order to continue working I need to end the program and restart it. It doesn’t happen every time, but it happens a lot.
Version details:
MATLAB Version: 7.11.0.584 (R2010b)
Operating System: Microsoft Windows XP Version 5.1 (Build 2600: Service Pack 3)
Java VM Version: Java 1.6.0_17-b04 with Sun Microsystems Inc. Java HotSpot(TM) Client VM mixed mode.
Did someone ever encounter a similar problem?
Thanks! debugging, error MATLAB Answers — New Questions
pwelch method of power spectral density (psd) calculation
I have a question on the pwelch method for power spectral density computation in Matlab that is not clarified in the documentation for pwelch.
My usage : pxx = pwelch(x, window, noverlap, nfft)
If nfft is larger than the length of window, I believe MATLAB pads each windowed segment with zeros so that the FFT is taken on nfft points. Please confirm.
What happens when nfft is smaller than the window length? Is the window size truncated to match nfft?
pwelch appears to scale the DFT here appropriately with number of samples of the nfft (N) and frequency spacing as opposed to a regular DFT in Matlab that is not scaled, pl confirm.
Is there a way to output the number of averages performed when pwelch is called as above?
Thanks.I have a question on the pwelch method for power spectral density computation in Matlab that is not clarified in the documentation for pwelch.
My usage : pxx = pwelch(x, window, noverlap, nfft)
If nfft is larger than the length of window, I believe MATLAB pads each windowed segment with zeros so that the FFT is taken on nfft points. Please confirm.
What happens when nfft is smaller than the window length? Is the window size truncated to match nfft?
pwelch appears to scale the DFT here appropriately with number of samples of the nfft (N) and frequency spacing as opposed to a regular DFT in Matlab that is not scaled, pl confirm.
Is there a way to output the number of averages performed when pwelch is called as above?
Thanks. I have a question on the pwelch method for power spectral density computation in Matlab that is not clarified in the documentation for pwelch.
My usage : pxx = pwelch(x, window, noverlap, nfft)
If nfft is larger than the length of window, I believe MATLAB pads each windowed segment with zeros so that the FFT is taken on nfft points. Please confirm.
What happens when nfft is smaller than the window length? Is the window size truncated to match nfft?
pwelch appears to scale the DFT here appropriately with number of samples of the nfft (N) and frequency spacing as opposed to a regular DFT in Matlab that is not scaled, pl confirm.
Is there a way to output the number of averages performed when pwelch is called as above?
Thanks. pwelch, psd, fft MATLAB Answers — New Questions
Simulink Playback Block Dropping Ports
When I save a model and close it, the next time I open it my playback block outputs say ground and I have to go manually reconnect them to the data in the workspace.
This seems to be a new issue in 2024b as we’ve used Playback blocks for years without issue.
The blocks work fine as long as the model is open, but when I close it, there is a good chance the Playback block loses it’s outputs. It doesn’t happen every time, but it’s > 1 out of 3.When I save a model and close it, the next time I open it my playback block outputs say ground and I have to go manually reconnect them to the data in the workspace.
This seems to be a new issue in 2024b as we’ve used Playback blocks for years without issue.
The blocks work fine as long as the model is open, but when I close it, there is a good chance the Playback block loses it’s outputs. It doesn’t happen every time, but it’s > 1 out of 3. When I save a model and close it, the next time I open it my playback block outputs say ground and I have to go manually reconnect them to the data in the workspace.
This seems to be a new issue in 2024b as we’ve used Playback blocks for years without issue.
The blocks work fine as long as the model is open, but when I close it, there is a good chance the Playback block loses it’s outputs. It doesn’t happen every time, but it’s > 1 out of 3. simulink, playback block MATLAB Answers — New Questions
Efficient overlapping block processing with nested sub blocks (similar to im2col with stride)
Hello, I recently have been doing a side project to teach myself some more efficient and performance optimized MATLAB and I ran into the following problem. My solution feels "ugly" to me and I highly suspect that there is a better version. I am intentionally straying from builtin functions like im2col and blockproc but I definitely am not asking you to restrict your solutions especially if they are high performance.
Problem:
An example of the input to the problem is generated by the following code. It consists of square matrix with nxn blocks. I use ascending integers to make it easier to keep track of the format of the data.
% example input matrix A with nxn blocks
n = 2;
N = 2*n^2;
A = kron((1:n^2).’,ones(1,2*N)) + (1:n^2:N^2) – 1;
[row,col] = ind2sub([n n],1:n^2);
A((row-1).*n+col,:) = A((col-1).*n+row,:);
A = col2im(A, [n n], [N N], ‘distinct’).’
The desired output from the input is to take a sliding block of 2n x 2n with a stride of n in both the x and y directions. This generates a block with 4 subblocks of size n x n. I would like to generate a similar result of im2col, but with the caveat that the column result keeps the individual sub blocks together (as if I had taken im2col of each of the sub blocks and then stacked them into a single column). Normally im2col scans the matrix top to bottom and left to right, but the final desired requirement is that the columns come from a sweep from left to right and then top to bottom.
My solution is:
% intermediate matrix B with 2n patches with n stride
M = length(A(:,1)) + n;
A(end+1:M,end+1:M) = 0;
[x,y] = meshgrid(1:2*n);
[xs,ys] = meshgrid(0:n:(M-2*n));
idx = (reshape(y,4*n^2,[]) + ys(:)’) + (M*reshape(x-1,4*n^2,[]) + M*xs(:)’);
colB = A(idx);
% these 2 lines not part of my solution but may help visualize the
% intermediate step of expanding the matrix
szB = sqrt(numel(colB));
B = col2im(colB, [2*n 2*n], [szB szB], ‘distinct’);
% reshape and permute chain for desired format and ordering
C = reshape(colB,n,2,[]);
C = permute(C,[1 3 2]);
C = reshape(C, 4*n^2, n, []);
C = permute(C, [1 3 2]);
C = reshape(C, 4*n^2,[]) % final desired output
The final result is good for general n and the solution runs decently fast. However it just looks like there is still performance to squeeze out of this. I feel like there is a more direct method than constructing the intermediate matrix and then decomposing it. I also feel like there is a better reordering process than my reshape->permute->reshape->permute->reshape. After too many hours trying I am forced to concede but hopefully someone here can teach me something new. Thanks in advance.Hello, I recently have been doing a side project to teach myself some more efficient and performance optimized MATLAB and I ran into the following problem. My solution feels "ugly" to me and I highly suspect that there is a better version. I am intentionally straying from builtin functions like im2col and blockproc but I definitely am not asking you to restrict your solutions especially if they are high performance.
Problem:
An example of the input to the problem is generated by the following code. It consists of square matrix with nxn blocks. I use ascending integers to make it easier to keep track of the format of the data.
% example input matrix A with nxn blocks
n = 2;
N = 2*n^2;
A = kron((1:n^2).’,ones(1,2*N)) + (1:n^2:N^2) – 1;
[row,col] = ind2sub([n n],1:n^2);
A((row-1).*n+col,:) = A((col-1).*n+row,:);
A = col2im(A, [n n], [N N], ‘distinct’).’
The desired output from the input is to take a sliding block of 2n x 2n with a stride of n in both the x and y directions. This generates a block with 4 subblocks of size n x n. I would like to generate a similar result of im2col, but with the caveat that the column result keeps the individual sub blocks together (as if I had taken im2col of each of the sub blocks and then stacked them into a single column). Normally im2col scans the matrix top to bottom and left to right, but the final desired requirement is that the columns come from a sweep from left to right and then top to bottom.
My solution is:
% intermediate matrix B with 2n patches with n stride
M = length(A(:,1)) + n;
A(end+1:M,end+1:M) = 0;
[x,y] = meshgrid(1:2*n);
[xs,ys] = meshgrid(0:n:(M-2*n));
idx = (reshape(y,4*n^2,[]) + ys(:)’) + (M*reshape(x-1,4*n^2,[]) + M*xs(:)’);
colB = A(idx);
% these 2 lines not part of my solution but may help visualize the
% intermediate step of expanding the matrix
szB = sqrt(numel(colB));
B = col2im(colB, [2*n 2*n], [szB szB], ‘distinct’);
% reshape and permute chain for desired format and ordering
C = reshape(colB,n,2,[]);
C = permute(C,[1 3 2]);
C = reshape(C, 4*n^2, n, []);
C = permute(C, [1 3 2]);
C = reshape(C, 4*n^2,[]) % final desired output
The final result is good for general n and the solution runs decently fast. However it just looks like there is still performance to squeeze out of this. I feel like there is a more direct method than constructing the intermediate matrix and then decomposing it. I also feel like there is a better reordering process than my reshape->permute->reshape->permute->reshape. After too many hours trying I am forced to concede but hopefully someone here can teach me something new. Thanks in advance. Hello, I recently have been doing a side project to teach myself some more efficient and performance optimized MATLAB and I ran into the following problem. My solution feels "ugly" to me and I highly suspect that there is a better version. I am intentionally straying from builtin functions like im2col and blockproc but I definitely am not asking you to restrict your solutions especially if they are high performance.
Problem:
An example of the input to the problem is generated by the following code. It consists of square matrix with nxn blocks. I use ascending integers to make it easier to keep track of the format of the data.
% example input matrix A with nxn blocks
n = 2;
N = 2*n^2;
A = kron((1:n^2).’,ones(1,2*N)) + (1:n^2:N^2) – 1;
[row,col] = ind2sub([n n],1:n^2);
A((row-1).*n+col,:) = A((col-1).*n+row,:);
A = col2im(A, [n n], [N N], ‘distinct’).’
The desired output from the input is to take a sliding block of 2n x 2n with a stride of n in both the x and y directions. This generates a block with 4 subblocks of size n x n. I would like to generate a similar result of im2col, but with the caveat that the column result keeps the individual sub blocks together (as if I had taken im2col of each of the sub blocks and then stacked them into a single column). Normally im2col scans the matrix top to bottom and left to right, but the final desired requirement is that the columns come from a sweep from left to right and then top to bottom.
My solution is:
% intermediate matrix B with 2n patches with n stride
M = length(A(:,1)) + n;
A(end+1:M,end+1:M) = 0;
[x,y] = meshgrid(1:2*n);
[xs,ys] = meshgrid(0:n:(M-2*n));
idx = (reshape(y,4*n^2,[]) + ys(:)’) + (M*reshape(x-1,4*n^2,[]) + M*xs(:)’);
colB = A(idx);
% these 2 lines not part of my solution but may help visualize the
% intermediate step of expanding the matrix
szB = sqrt(numel(colB));
B = col2im(colB, [2*n 2*n], [szB szB], ‘distinct’);
% reshape and permute chain for desired format and ordering
C = reshape(colB,n,2,[]);
C = permute(C,[1 3 2]);
C = reshape(C, 4*n^2, n, []);
C = permute(C, [1 3 2]);
C = reshape(C, 4*n^2,[]) % final desired output
The final result is good for general n and the solution runs decently fast. However it just looks like there is still performance to squeeze out of this. I feel like there is a more direct method than constructing the intermediate matrix and then decomposing it. I also feel like there is a better reordering process than my reshape->permute->reshape->permute->reshape. After too many hours trying I am forced to concede but hopefully someone here can teach me something new. Thanks in advance. reshaping, im2col, block processing MATLAB Answers — New Questions
how to make a plot with three variables, one as a vector, in Matlab app designer?
Hi
I have some data, some arrays with name temperature, activity and then I have two arrrays named weight percent best_salt_1 and weight percent best_salt_2 that I will combine into a vector or to an array with one row and two columns for each set of values . And then I want to plot the data to visualise the information. But I dont have the newest version of Matlab , dont want to upgrade my version either. Hence I cant use the gscatter function that can make it possible to visualize all the info I want in my plot.
Then my question if whether I can use a trick like splitapply so everything I want to visualise here is possible..?Hi
I have some data, some arrays with name temperature, activity and then I have two arrrays named weight percent best_salt_1 and weight percent best_salt_2 that I will combine into a vector or to an array with one row and two columns for each set of values . And then I want to plot the data to visualise the information. But I dont have the newest version of Matlab , dont want to upgrade my version either. Hence I cant use the gscatter function that can make it possible to visualize all the info I want in my plot.
Then my question if whether I can use a trick like splitapply so everything I want to visualise here is possible..? Hi
I have some data, some arrays with name temperature, activity and then I have two arrrays named weight percent best_salt_1 and weight percent best_salt_2 that I will combine into a vector or to an array with one row and two columns for each set of values . And then I want to plot the data to visualise the information. But I dont have the newest version of Matlab , dont want to upgrade my version either. Hence I cant use the gscatter function that can make it possible to visualize all the info I want in my plot.
Then my question if whether I can use a trick like splitapply so everything I want to visualise here is possible..? plot, appdesigner, three variables, matlab 2018 MATLAB Answers — New Questions
Odd behavior of unstack in Matlab2025b
Hello,
When calling the unstack function using @sum as the AggregationFunction for numerical values in 2025b, I’m getting the warning below and the empty groups get a zero (from summing into a 0-1 input)
Warning: When a group has no rows for a given value of the indicator variable, UNSTACK calls the supplied aggregation function with an input of size 0-by-1 instead of automatically filling the value.
Review the output to ensure desired result is obtained. This warning might be removed in a future release.
However the function documentation states the following:
Missing value of the appropriate data type, such as a NaN, NaT, missing string, or undefined categorical value.
Which is the behavior I used to get in previous Matlab versions (e.g. 2019b), would get NaNs from empty groups, and which I would have epxected to happend here since its what the documentation suggests.
Any thoughts on why this might be happening or if I can change the behavior so as to get NaNs instead of calling the aggregation function into a 0-1 input for the empty groups?Hello,
When calling the unstack function using @sum as the AggregationFunction for numerical values in 2025b, I’m getting the warning below and the empty groups get a zero (from summing into a 0-1 input)
Warning: When a group has no rows for a given value of the indicator variable, UNSTACK calls the supplied aggregation function with an input of size 0-by-1 instead of automatically filling the value.
Review the output to ensure desired result is obtained. This warning might be removed in a future release.
However the function documentation states the following:
Missing value of the appropriate data type, such as a NaN, NaT, missing string, or undefined categorical value.
Which is the behavior I used to get in previous Matlab versions (e.g. 2019b), would get NaNs from empty groups, and which I would have epxected to happend here since its what the documentation suggests.
Any thoughts on why this might be happening or if I can change the behavior so as to get NaNs instead of calling the aggregation function into a 0-1 input for the empty groups? Hello,
When calling the unstack function using @sum as the AggregationFunction for numerical values in 2025b, I’m getting the warning below and the empty groups get a zero (from summing into a 0-1 input)
Warning: When a group has no rows for a given value of the indicator variable, UNSTACK calls the supplied aggregation function with an input of size 0-by-1 instead of automatically filling the value.
Review the output to ensure desired result is obtained. This warning might be removed in a future release.
However the function documentation states the following:
Missing value of the appropriate data type, such as a NaN, NaT, missing string, or undefined categorical value.
Which is the behavior I used to get in previous Matlab versions (e.g. 2019b), would get NaNs from empty groups, and which I would have epxected to happend here since its what the documentation suggests.
Any thoughts on why this might be happening or if I can change the behavior so as to get NaNs instead of calling the aggregation function into a 0-1 input for the empty groups? unstack, 2025b MATLAB Answers — New Questions
SNR goes down as noise filtering is increased.
Hello friends. I have a question regarding filtering noise from noisy signals. I filtered a signal (data attached to this post) using Wiener2 with a window size of 3 and 11. I then subtracted the filtered signal from the orginal signal to get noise. Surprisingly, the SNR for the more filtered signal (corresponding to window size of 11) is lesser than the least filtered. Could this be due to the signal getting attenuated along with the noise ? Any direction to this issue will be much appreciated. The code is also attached. Thank you.
%% SNR comparision befrore and after filtering noise
%noisydata = readmatrix("Data_response_thickJn_1W_IPA_set1_5.csv");
load ("noisyData.mat")
noisydata = data;
time = noisydata(:,1);
temp = noisydata(:,2);
% filtering using Wiener filter
filteredTemp1 = wiener2(temp,[3,1]); %low filter window
noise1 = temp – filteredTemp1;
SNR1 = snr(temp,noise1)
filteredTemp2 = wiener2(temp,[11,1]); %high filter window
noise2 = temp – filteredTemp2;
SNR2 = snr(temp,noise2)Hello friends. I have a question regarding filtering noise from noisy signals. I filtered a signal (data attached to this post) using Wiener2 with a window size of 3 and 11. I then subtracted the filtered signal from the orginal signal to get noise. Surprisingly, the SNR for the more filtered signal (corresponding to window size of 11) is lesser than the least filtered. Could this be due to the signal getting attenuated along with the noise ? Any direction to this issue will be much appreciated. The code is also attached. Thank you.
%% SNR comparision befrore and after filtering noise
%noisydata = readmatrix("Data_response_thickJn_1W_IPA_set1_5.csv");
load ("noisyData.mat")
noisydata = data;
time = noisydata(:,1);
temp = noisydata(:,2);
% filtering using Wiener filter
filteredTemp1 = wiener2(temp,[3,1]); %low filter window
noise1 = temp – filteredTemp1;
SNR1 = snr(temp,noise1)
filteredTemp2 = wiener2(temp,[11,1]); %high filter window
noise2 = temp – filteredTemp2;
SNR2 = snr(temp,noise2) Hello friends. I have a question regarding filtering noise from noisy signals. I filtered a signal (data attached to this post) using Wiener2 with a window size of 3 and 11. I then subtracted the filtered signal from the orginal signal to get noise. Surprisingly, the SNR for the more filtered signal (corresponding to window size of 11) is lesser than the least filtered. Could this be due to the signal getting attenuated along with the noise ? Any direction to this issue will be much appreciated. The code is also attached. Thank you.
%% SNR comparision befrore and after filtering noise
%noisydata = readmatrix("Data_response_thickJn_1W_IPA_set1_5.csv");
load ("noisyData.mat")
noisydata = data;
time = noisydata(:,1);
temp = noisydata(:,2);
% filtering using Wiener filter
filteredTemp1 = wiener2(temp,[3,1]); %low filter window
noise1 = temp – filteredTemp1;
SNR1 = snr(temp,noise1)
filteredTemp2 = wiener2(temp,[11,1]); %high filter window
noise2 = temp – filteredTemp2;
SNR2 = snr(temp,noise2) digital signal processing, noise, filtering MATLAB Answers — New Questions
import Robot from URDF file
In the ‘PickandPlaceWorkflowInUnity3DUsingROSExample’,I have some problem at importing Robot from URDF file,the model cann’t be fully imported in the unity.In the ‘PickandPlaceWorkflowInUnity3DUsingROSExample’,I have some problem at importing Robot from URDF file,the model cann’t be fully imported in the unity. In the ‘PickandPlaceWorkflowInUnity3DUsingROSExample’,I have some problem at importing Robot from URDF file,the model cann’t be fully imported in the unity. unity, matlab MATLAB Answers — New Questions
Variables of varying size in Simulink – avoiding preallocation
I have a matlab script that controls a Simulink model for code generation. Currently I preassign a varaible X to be the maximum possible size of the array (100 rows) along with a constant 8 columns. A coplicated for loop code block runs to decide which of the variables looped over will get added to the variable X. Depeding on settings this can be anywhere between 6 rows and 100 rows filled. It seems very cumbersome to have a 100×8 permanently when there is eg only info in the top 6×8 portion as this matrix then gets used by other Simulink submodels. All my attempts at creating a varaible array size have come up against issues with errors such as ‘Error in port dimensions’. Is there any way for Simulink to avoid preallocating the variable size or reducing the size of the array once populated.I have a matlab script that controls a Simulink model for code generation. Currently I preassign a varaible X to be the maximum possible size of the array (100 rows) along with a constant 8 columns. A coplicated for loop code block runs to decide which of the variables looped over will get added to the variable X. Depeding on settings this can be anywhere between 6 rows and 100 rows filled. It seems very cumbersome to have a 100×8 permanently when there is eg only info in the top 6×8 portion as this matrix then gets used by other Simulink submodels. All my attempts at creating a varaible array size have come up against issues with errors such as ‘Error in port dimensions’. Is there any way for Simulink to avoid preallocating the variable size or reducing the size of the array once populated. I have a matlab script that controls a Simulink model for code generation. Currently I preassign a varaible X to be the maximum possible size of the array (100 rows) along with a constant 8 columns. A coplicated for loop code block runs to decide which of the variables looped over will get added to the variable X. Depeding on settings this can be anywhere between 6 rows and 100 rows filled. It seems very cumbersome to have a 100×8 permanently when there is eg only info in the top 6×8 portion as this matrix then gets used by other Simulink submodels. All my attempts at creating a varaible array size have come up against issues with errors such as ‘Error in port dimensions’. Is there any way for Simulink to avoid preallocating the variable size or reducing the size of the array once populated. simulink, variable, matrix array MATLAB Answers — New Questions
Direct Dynamics of Two-Link Manipulator
Hi,
I am unsuccesful in using a MATLAB function block in Simulink to model the direct dynamics of a two-link planar manipulator. The function takes the gear ratio (), 2×1 motor torque (), angular position ($v$) and angular velocity ($dot v$) and outputs the angular acceleration ($ddot v$). See below for my Simulink model.The torque step function has a step time of 0.1, initial value of [0;0]. final value of [15;10] and also a sample time of 0.1. = 10 is a constant. The first integrator has initial conditions [-pi/2,0] and the second has initial conditions of [0,0]. I am outputting the torque, joint velocity and the joint position to the workspace.
I am getting the correct vector for torque: $[tao_1, tao_2] = [0,0]$ at time 0 and $[tao_1, tao_2] = [15,10]$ after that. However the joint 1 position is decreasing from 0 to -15 and the joint 2 position is staying at 0. The joint 1 and 2 velocities are staying constant at the initial velocity of -pi/2,0. I have pasted my code that I have gone over numerous times so I doubt there is any issue there. I think the issue is more in the setup for the Simulink.
Was wondering if people can help pinpoint the problem and help lead me in the right direction.
function v_ddot = dynamics(n, t_m, v_dot, v)
%given constants
ml1 = 49; ml2 = 34;
a1 = 1; a2 = 1;
l1 = 0.5; l2 = 0.5;
Iyy_1 = 4.08; Iyy_2 = 2.83;
Im1 = 0.25; Im2 = 0.25;
b1 = 12; b2 = 12;
bm1 = 0.08; bm2 = 0.08;
g = 9.8;
%calculations for lumped parameters I1 and I2
I1 = Iyy_1 + ml1 * l1^2 + ml2 * a1^2;
I2 = Iyy_2 + ml2 * l2^2;
h = ml2*a1*l2;
%mass, centrifugal/coriolis, gravitational, friction vectors
M = [n^2*Im1 + I1 + I2 + 2*h*cos(v(2)), I2 + h*cos(v(2)); I2 + h*cos(v(2)), n^2*Im2 + I2];
V = h*sin(v(2))*[-2*v_dot(1)*v_dot(2) – v_dot(2)^2; v_dot(1)^2];
G = [(ml1*l1 + ml2*l2)*cos(v(1))*g + ml2*l2*cos(v(1)+v(2))*g; ml2*l2*cos(v(1)+v(2))*g];
F = [b1*v_dot(1) + n^2*bm1; b2*v_dot(2) + n^2*bm2*v_dot(2)];
%solving for the angualar accelerations
v_ddot = M (-V – G – F + t_m * n);
endHi,
I am unsuccesful in using a MATLAB function block in Simulink to model the direct dynamics of a two-link planar manipulator. The function takes the gear ratio (), 2×1 motor torque (), angular position ($v$) and angular velocity ($dot v$) and outputs the angular acceleration ($ddot v$). See below for my Simulink model.The torque step function has a step time of 0.1, initial value of [0;0]. final value of [15;10] and also a sample time of 0.1. = 10 is a constant. The first integrator has initial conditions [-pi/2,0] and the second has initial conditions of [0,0]. I am outputting the torque, joint velocity and the joint position to the workspace.
I am getting the correct vector for torque: $[tao_1, tao_2] = [0,0]$ at time 0 and $[tao_1, tao_2] = [15,10]$ after that. However the joint 1 position is decreasing from 0 to -15 and the joint 2 position is staying at 0. The joint 1 and 2 velocities are staying constant at the initial velocity of -pi/2,0. I have pasted my code that I have gone over numerous times so I doubt there is any issue there. I think the issue is more in the setup for the Simulink.
Was wondering if people can help pinpoint the problem and help lead me in the right direction.
function v_ddot = dynamics(n, t_m, v_dot, v)
%given constants
ml1 = 49; ml2 = 34;
a1 = 1; a2 = 1;
l1 = 0.5; l2 = 0.5;
Iyy_1 = 4.08; Iyy_2 = 2.83;
Im1 = 0.25; Im2 = 0.25;
b1 = 12; b2 = 12;
bm1 = 0.08; bm2 = 0.08;
g = 9.8;
%calculations for lumped parameters I1 and I2
I1 = Iyy_1 + ml1 * l1^2 + ml2 * a1^2;
I2 = Iyy_2 + ml2 * l2^2;
h = ml2*a1*l2;
%mass, centrifugal/coriolis, gravitational, friction vectors
M = [n^2*Im1 + I1 + I2 + 2*h*cos(v(2)), I2 + h*cos(v(2)); I2 + h*cos(v(2)), n^2*Im2 + I2];
V = h*sin(v(2))*[-2*v_dot(1)*v_dot(2) – v_dot(2)^2; v_dot(1)^2];
G = [(ml1*l1 + ml2*l2)*cos(v(1))*g + ml2*l2*cos(v(1)+v(2))*g; ml2*l2*cos(v(1)+v(2))*g];
F = [b1*v_dot(1) + n^2*bm1; b2*v_dot(2) + n^2*bm2*v_dot(2)];
%solving for the angualar accelerations
v_ddot = M (-V – G – F + t_m * n);
end Hi,
I am unsuccesful in using a MATLAB function block in Simulink to model the direct dynamics of a two-link planar manipulator. The function takes the gear ratio (), 2×1 motor torque (), angular position ($v$) and angular velocity ($dot v$) and outputs the angular acceleration ($ddot v$). See below for my Simulink model.The torque step function has a step time of 0.1, initial value of [0;0]. final value of [15;10] and also a sample time of 0.1. = 10 is a constant. The first integrator has initial conditions [-pi/2,0] and the second has initial conditions of [0,0]. I am outputting the torque, joint velocity and the joint position to the workspace.
I am getting the correct vector for torque: $[tao_1, tao_2] = [0,0]$ at time 0 and $[tao_1, tao_2] = [15,10]$ after that. However the joint 1 position is decreasing from 0 to -15 and the joint 2 position is staying at 0. The joint 1 and 2 velocities are staying constant at the initial velocity of -pi/2,0. I have pasted my code that I have gone over numerous times so I doubt there is any issue there. I think the issue is more in the setup for the Simulink.
Was wondering if people can help pinpoint the problem and help lead me in the right direction.
function v_ddot = dynamics(n, t_m, v_dot, v)
%given constants
ml1 = 49; ml2 = 34;
a1 = 1; a2 = 1;
l1 = 0.5; l2 = 0.5;
Iyy_1 = 4.08; Iyy_2 = 2.83;
Im1 = 0.25; Im2 = 0.25;
b1 = 12; b2 = 12;
bm1 = 0.08; bm2 = 0.08;
g = 9.8;
%calculations for lumped parameters I1 and I2
I1 = Iyy_1 + ml1 * l1^2 + ml2 * a1^2;
I2 = Iyy_2 + ml2 * l2^2;
h = ml2*a1*l2;
%mass, centrifugal/coriolis, gravitational, friction vectors
M = [n^2*Im1 + I1 + I2 + 2*h*cos(v(2)), I2 + h*cos(v(2)); I2 + h*cos(v(2)), n^2*Im2 + I2];
V = h*sin(v(2))*[-2*v_dot(1)*v_dot(2) – v_dot(2)^2; v_dot(1)^2];
G = [(ml1*l1 + ml2*l2)*cos(v(1))*g + ml2*l2*cos(v(1)+v(2))*g; ml2*l2*cos(v(1)+v(2))*g];
F = [b1*v_dot(1) + n^2*bm1; b2*v_dot(2) + n^2*bm2*v_dot(2)];
%solving for the angualar accelerations
v_ddot = M (-V – G – F + t_m * n);
end simulink MATLAB Answers — New Questions
Trying to filter timeseries data by logical index on time within matlab function block but it tells me property Time not recognized as valid
I’m trying to load a year-long timeseries from a .mat file and then select a single day’s data from that file within a matlab function block. The loaded timeseries data is one input to the block (tsinput) and a number indicating the day of interest in MMDD format is the other input (daynum). My function block code is:
function tsoutput = fcn(tsinput, daynum)
%find the doy for the daystr input
datestr = strcat(daynum,’2023′);
coder.extrinsic(‘datetime’);
datedt = datetime(datestr, ‘InputFormat’, ‘MMddyyyy’);
coder.extrinsic(‘day’);
datedoy = day(datedt,’dayofyear’);
mask = tsinput.Time>datedoy & tsinput.Time<datedoy+1;
% Create a new timeseries with only those samples
tsoutput = getsamples(tsinput, mask);
But when I try running my simulink code, which is just a from file block and constant number block with the matlab function block, I get these errors:
Simulink does not have enough information to determine output sizes for this block. If you think the errors below are inaccurate, try specifying types for the block inputs and/or sizes for the block outputs.
Component:MATLAB Function | Category:Coder error
Property ‘Time’ is not recognized as valid.
Function ‘MATLAB Function’ (#36.261.273), line 10, column 8:
"tsinput.Time"
Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Errors occurred during parsing of ‘testdataload/MATLAB Function’.
Component:MATLAB Function | Category:Coder error
Simulink is unable to determine sizes and/or types of the outputs for block ‘testdataload/MATLAB Function’ due to errors in the block body, or limitations of the underlying analysis. The errors might be inaccurate. Fix the indicated errors, or explicitly specify sizes and/or types for all block outputs.
Component:MATLAB Function | Category:Coder error
Simulink is unable to determine sizes and/or types of the outputs for block ‘testdataload/MATLAB Function’ due to errors in the block body, or limitations of the underlying analysis. The errors might be inaccurate. Fix the indicated errors, or explicitly specify sizes and/or types for all block outputs.
Component:Simulink | Category:Model error
Error in port widths or dimensions. ‘Output Port 1’ of ‘testdataload/MATLAB Function/tsinput’ is a one dimensional vector with 1 elements.
Component:Simulink | Category:Model errorI’m trying to load a year-long timeseries from a .mat file and then select a single day’s data from that file within a matlab function block. The loaded timeseries data is one input to the block (tsinput) and a number indicating the day of interest in MMDD format is the other input (daynum). My function block code is:
function tsoutput = fcn(tsinput, daynum)
%find the doy for the daystr input
datestr = strcat(daynum,’2023′);
coder.extrinsic(‘datetime’);
datedt = datetime(datestr, ‘InputFormat’, ‘MMddyyyy’);
coder.extrinsic(‘day’);
datedoy = day(datedt,’dayofyear’);
mask = tsinput.Time>datedoy & tsinput.Time<datedoy+1;
% Create a new timeseries with only those samples
tsoutput = getsamples(tsinput, mask);
But when I try running my simulink code, which is just a from file block and constant number block with the matlab function block, I get these errors:
Simulink does not have enough information to determine output sizes for this block. If you think the errors below are inaccurate, try specifying types for the block inputs and/or sizes for the block outputs.
Component:MATLAB Function | Category:Coder error
Property ‘Time’ is not recognized as valid.
Function ‘MATLAB Function’ (#36.261.273), line 10, column 8:
"tsinput.Time"
Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Errors occurred during parsing of ‘testdataload/MATLAB Function’.
Component:MATLAB Function | Category:Coder error
Simulink is unable to determine sizes and/or types of the outputs for block ‘testdataload/MATLAB Function’ due to errors in the block body, or limitations of the underlying analysis. The errors might be inaccurate. Fix the indicated errors, or explicitly specify sizes and/or types for all block outputs.
Component:MATLAB Function | Category:Coder error
Simulink is unable to determine sizes and/or types of the outputs for block ‘testdataload/MATLAB Function’ due to errors in the block body, or limitations of the underlying analysis. The errors might be inaccurate. Fix the indicated errors, or explicitly specify sizes and/or types for all block outputs.
Component:Simulink | Category:Model error
Error in port widths or dimensions. ‘Output Port 1’ of ‘testdataload/MATLAB Function/tsinput’ is a one dimensional vector with 1 elements.
Component:Simulink | Category:Model error I’m trying to load a year-long timeseries from a .mat file and then select a single day’s data from that file within a matlab function block. The loaded timeseries data is one input to the block (tsinput) and a number indicating the day of interest in MMDD format is the other input (daynum). My function block code is:
function tsoutput = fcn(tsinput, daynum)
%find the doy for the daystr input
datestr = strcat(daynum,’2023′);
coder.extrinsic(‘datetime’);
datedt = datetime(datestr, ‘InputFormat’, ‘MMddyyyy’);
coder.extrinsic(‘day’);
datedoy = day(datedt,’dayofyear’);
mask = tsinput.Time>datedoy & tsinput.Time<datedoy+1;
% Create a new timeseries with only those samples
tsoutput = getsamples(tsinput, mask);
But when I try running my simulink code, which is just a from file block and constant number block with the matlab function block, I get these errors:
Simulink does not have enough information to determine output sizes for this block. If you think the errors below are inaccurate, try specifying types for the block inputs and/or sizes for the block outputs.
Component:MATLAB Function | Category:Coder error
Property ‘Time’ is not recognized as valid.
Function ‘MATLAB Function’ (#36.261.273), line 10, column 8:
"tsinput.Time"
Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Errors occurred during parsing of ‘testdataload/MATLAB Function’.
Component:MATLAB Function | Category:Coder error
Simulink is unable to determine sizes and/or types of the outputs for block ‘testdataload/MATLAB Function’ due to errors in the block body, or limitations of the underlying analysis. The errors might be inaccurate. Fix the indicated errors, or explicitly specify sizes and/or types for all block outputs.
Component:MATLAB Function | Category:Coder error
Simulink is unable to determine sizes and/or types of the outputs for block ‘testdataload/MATLAB Function’ due to errors in the block body, or limitations of the underlying analysis. The errors might be inaccurate. Fix the indicated errors, or explicitly specify sizes and/or types for all block outputs.
Component:Simulink | Category:Model error
Error in port widths or dimensions. ‘Output Port 1’ of ‘testdataload/MATLAB Function/tsinput’ is a one dimensional vector with 1 elements.
Component:Simulink | Category:Model error simulink, matlab function block, timeseries, logical index MATLAB Answers — New Questions
install_addon(‘smlink.r2017b.win64.zip’) Undefined function or variable ‘install_addon’
any one who can help me to interface matlab and solidwork
i use >>install_addon(‘smlink.r2017b.win64.zip’)
in command window but it displays
Undefined function or variable ‘install_addon’any one who can help me to interface matlab and solidwork
i use >>install_addon(‘smlink.r2017b.win64.zip’)
in command window but it displays
Undefined function or variable ‘install_addon’ any one who can help me to interface matlab and solidwork
i use >>install_addon(‘smlink.r2017b.win64.zip’)
in command window but it displays
Undefined function or variable ‘install_addon’ solid MATLAB Answers — New Questions
matlab/simulink+tensorflow problem
My MATLAB can connect to Python and execute Python statements, but it encounters an error when importing TensorFlow. How can I resolve this?
In the MATLAB command line, when I enter:
py.importlib.import_module(‘tensorflow’)
an error occurs:
“error to use pywrap_tensorflow><module> (line 88)
Python error ImportError: Traceback (most recent call last):
File "C:UsersLENOVO.condaenvsmatlab_testlibsite-packagestensorflowpythonpywrap_tensorflow.py", line 73, in <module>
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed while importing _pywrap_tensorflow_internal: Dynamic link library (DLL) initialization routine failed.
Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/errors for some common causes and solutions.
If you need help, create an issue at https://github.com/tensorflow/tensorflow/issues and include the entire stack trace above this error
message.
Error in __init__><module> (line 40)
Error in <frozen importlib>_call_with_frames_removed (line 228)
Error in <frozen importlib>exec_module (line 850)
Error in <frozen importlib>_load_unlocked (line 680)
Error in <frozen importlib>_find_and_load_unlocked (line 986)
Error in <frozen importlib>_find_and_load (line 1007)
Error in <frozen importlib>_gcd_import (line 1030)
Error in __init__>import_module (line 127)
”
My matlab version is R2024a, python== 3.9, tensorflow-cpu==2.19
When I import TensorFlow in the Python command line, there is no problem, but when I do so in MATLAB, the above error occurs.
I’ve tried a few solutions, but none of them worked:
Install Microsoft Visual C++ Redistributable
Switch tensorflow from GPU version to CPU version
Use Anaconda to isolate dependencies for different projects.
please help me !!!!!My MATLAB can connect to Python and execute Python statements, but it encounters an error when importing TensorFlow. How can I resolve this?
In the MATLAB command line, when I enter:
py.importlib.import_module(‘tensorflow’)
an error occurs:
“error to use pywrap_tensorflow><module> (line 88)
Python error ImportError: Traceback (most recent call last):
File "C:UsersLENOVO.condaenvsmatlab_testlibsite-packagestensorflowpythonpywrap_tensorflow.py", line 73, in <module>
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed while importing _pywrap_tensorflow_internal: Dynamic link library (DLL) initialization routine failed.
Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/errors for some common causes and solutions.
If you need help, create an issue at https://github.com/tensorflow/tensorflow/issues and include the entire stack trace above this error
message.
Error in __init__><module> (line 40)
Error in <frozen importlib>_call_with_frames_removed (line 228)
Error in <frozen importlib>exec_module (line 850)
Error in <frozen importlib>_load_unlocked (line 680)
Error in <frozen importlib>_find_and_load_unlocked (line 986)
Error in <frozen importlib>_find_and_load (line 1007)
Error in <frozen importlib>_gcd_import (line 1030)
Error in __init__>import_module (line 127)
”
My matlab version is R2024a, python== 3.9, tensorflow-cpu==2.19
When I import TensorFlow in the Python command line, there is no problem, but when I do so in MATLAB, the above error occurs.
I’ve tried a few solutions, but none of them worked:
Install Microsoft Visual C++ Redistributable
Switch tensorflow from GPU version to CPU version
Use Anaconda to isolate dependencies for different projects.
please help me !!!!! My MATLAB can connect to Python and execute Python statements, but it encounters an error when importing TensorFlow. How can I resolve this?
In the MATLAB command line, when I enter:
py.importlib.import_module(‘tensorflow’)
an error occurs:
“error to use pywrap_tensorflow><module> (line 88)
Python error ImportError: Traceback (most recent call last):
File "C:UsersLENOVO.condaenvsmatlab_testlibsite-packagestensorflowpythonpywrap_tensorflow.py", line 73, in <module>
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed while importing _pywrap_tensorflow_internal: Dynamic link library (DLL) initialization routine failed.
Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/errors for some common causes and solutions.
If you need help, create an issue at https://github.com/tensorflow/tensorflow/issues and include the entire stack trace above this error
message.
Error in __init__><module> (line 40)
Error in <frozen importlib>_call_with_frames_removed (line 228)
Error in <frozen importlib>exec_module (line 850)
Error in <frozen importlib>_load_unlocked (line 680)
Error in <frozen importlib>_find_and_load_unlocked (line 986)
Error in <frozen importlib>_find_and_load (line 1007)
Error in <frozen importlib>_gcd_import (line 1030)
Error in __init__>import_module (line 127)
”
My matlab version is R2024a, python== 3.9, tensorflow-cpu==2.19
When I import TensorFlow in the Python command line, there is no problem, but when I do so in MATLAB, the above error occurs.
I’ve tried a few solutions, but none of them worked:
Install Microsoft Visual C++ Redistributable
Switch tensorflow from GPU version to CPU version
Use Anaconda to isolate dependencies for different projects.
please help me !!!!! deep learning, tensorflow MATLAB Answers — New Questions
How to understand the input and output arguments of preparets function for network training
For training NARX network, we need to prepare input and target time series data using preparets function. However, the preparets function has many input and output arguments which are confused for me to understand their functioning. I have read the examples about preparets, yet it is still difficult to understand. What is the best practice to understand the preparets and correctly use it under different network training scenarios ?
help preparets
EDIT: removed copyright code.For training NARX network, we need to prepare input and target time series data using preparets function. However, the preparets function has many input and output arguments which are confused for me to understand their functioning. I have read the examples about preparets, yet it is still difficult to understand. What is the best practice to understand the preparets and correctly use it under different network training scenarios ?
help preparets
EDIT: removed copyright code. For training NARX network, we need to prepare input and target time series data using preparets function. However, the preparets function has many input and output arguments which are confused for me to understand their functioning. I have read the examples about preparets, yet it is still difficult to understand. What is the best practice to understand the preparets and correctly use it under different network training scenarios ?
help preparets
EDIT: removed copyright code. network training, narx, preparets MATLAB Answers — New Questions
Patch FaceVertexCData being overwritten by FaceColor
Hello,
I am attempting to set up a patch with R2016b wherein one face of the patch has a certain color, and the rest share another. To do this I set up an (m x 3) array, "FacetColor," that assigned an RGB triplet to every face in the patch, according to its position in the geometry. The patch was then created with the code:
fv=struct(‘faces’,facet,’vertices’,vertex);
h=patch(fv,’FaceVertexCData’, FacetColor, …
‘EdgeColor’, ‘none’, …
‘FaceLighting’, ‘gouraud’, …
‘AmbientStrength’, 0.4);
alpha(h,1);
Unfortunately, whenever I attempt to run this code, MATLAB apparently ignores my FacetColor array and instead uses the default FaceColor value of [0 0 0]. This turns the entire patch uniformly black. I tried setting the FaceColor value to ‘none,’ thinking that doing so might force MATLAB to use the FaceVertexCData field, but instead it causes the patch to turn invisible. How am I configuring this patch incorrectly?
Any advice or assistance would be appreciated! My thanks in advance.Hello,
I am attempting to set up a patch with R2016b wherein one face of the patch has a certain color, and the rest share another. To do this I set up an (m x 3) array, "FacetColor," that assigned an RGB triplet to every face in the patch, according to its position in the geometry. The patch was then created with the code:
fv=struct(‘faces’,facet,’vertices’,vertex);
h=patch(fv,’FaceVertexCData’, FacetColor, …
‘EdgeColor’, ‘none’, …
‘FaceLighting’, ‘gouraud’, …
‘AmbientStrength’, 0.4);
alpha(h,1);
Unfortunately, whenever I attempt to run this code, MATLAB apparently ignores my FacetColor array and instead uses the default FaceColor value of [0 0 0]. This turns the entire patch uniformly black. I tried setting the FaceColor value to ‘none,’ thinking that doing so might force MATLAB to use the FaceVertexCData field, but instead it causes the patch to turn invisible. How am I configuring this patch incorrectly?
Any advice or assistance would be appreciated! My thanks in advance. Hello,
I am attempting to set up a patch with R2016b wherein one face of the patch has a certain color, and the rest share another. To do this I set up an (m x 3) array, "FacetColor," that assigned an RGB triplet to every face in the patch, according to its position in the geometry. The patch was then created with the code:
fv=struct(‘faces’,facet,’vertices’,vertex);
h=patch(fv,’FaceVertexCData’, FacetColor, …
‘EdgeColor’, ‘none’, …
‘FaceLighting’, ‘gouraud’, …
‘AmbientStrength’, 0.4);
alpha(h,1);
Unfortunately, whenever I attempt to run this code, MATLAB apparently ignores my FacetColor array and instead uses the default FaceColor value of [0 0 0]. This turns the entire patch uniformly black. I tried setting the FaceColor value to ‘none,’ thinking that doing so might force MATLAB to use the FaceVertexCData field, but instead it causes the patch to turn invisible. How am I configuring this patch incorrectly?
Any advice or assistance would be appreciated! My thanks in advance. patch, facevertexcdata, facecolor MATLAB Answers — New Questions
I have downloaded this package, but can not seem to use the “readDistance’ command.
I have downloaded this package, but can not seem to use the "readDistance’ command.
distance = readDistanceI have downloaded this package, but can not seem to use the "readDistance’ command.
distance = readDistance I have downloaded this package, but can not seem to use the "readDistance’ command.
distance = readDistance hc-sr04, error MATLAB Answers — New Questions
How can I see the (binomial) value of the AM2302 temperature sensor on the display?
Hi,
I’ve create a DHT11 Sensor Block with this documentation. Create DHT11 Block
But when I click on "Monitor and Tune", I have an error message, see in DHT11_model…txt.
Thanks for your help.Hi,
I’ve create a DHT11 Sensor Block with this documentation. Create DHT11 Block
But when I click on "Monitor and Tune", I have an error message, see in DHT11_model…txt.
Thanks for your help. Hi,
I’ve create a DHT11 Sensor Block with this documentation. Create DHT11 Block
But when I click on "Monitor and Tune", I have an error message, see in DHT11_model…txt.
Thanks for your help. value temperature MATLAB Answers — New Questions
How do I get the total impedance for one circuit of impedances?
I’m trying to get to total impedance where the impedance measurement block is but I can’t connect it to the circuit. Even the PS converter don’t seem to work to connect it to the block or the circuit. Any suggestion on how to make it work or which library and components use just putting the impedances and getting the total one?I’m trying to get to total impedance where the impedance measurement block is but I can’t connect it to the circuit. Even the PS converter don’t seem to work to connect it to the block or the circuit. Any suggestion on how to make it work or which library and components use just putting the impedances and getting the total one? I’m trying to get to total impedance where the impedance measurement block is but I can’t connect it to the circuit. Even the PS converter don’t seem to work to connect it to the block or the circuit. Any suggestion on how to make it work or which library and components use just putting the impedances and getting the total one? impedance, simulink MATLAB Answers — New Questions
In my COMSOL – PHREEQC Coupling using Matlab Interface, how to update solution for next time step??
I’m currently trying to use COMSOL – PHREEQC Coupling using Matlab Interface for reactive transport modeling. I’m trying Wissmeier & Barry (2011) approach for this. Currently, I’m facing the issue of solution from phreeqc is not being updated in comsol and the transport is not evolving in my simulation. I’m trying to simulate example 11 of phreeqc manual (Cation exchange). Can anyone help me with this?I’m currently trying to use COMSOL – PHREEQC Coupling using Matlab Interface for reactive transport modeling. I’m trying Wissmeier & Barry (2011) approach for this. Currently, I’m facing the issue of solution from phreeqc is not being updated in comsol and the transport is not evolving in my simulation. I’m trying to simulate example 11 of phreeqc manual (Cation exchange). Can anyone help me with this? I’m currently trying to use COMSOL – PHREEQC Coupling using Matlab Interface for reactive transport modeling. I’m trying Wissmeier & Barry (2011) approach for this. Currently, I’m facing the issue of solution from phreeqc is not being updated in comsol and the transport is not evolving in my simulation. I’m trying to simulate example 11 of phreeqc manual (Cation exchange). Can anyone help me with this? comsol, phreeqc, livelink, solution vector MATLAB Answers — New Questions
Request for MATLAB Code Review and Correction
The image contains the Transmission Line (TRL) equation. I am trying to develop a MATLAB code that matches this equation accurately. However, I need to verify that the implementation is consistent with the mathematical expression shown in the image.
Could you please review it and help ensure that the MATLAB code correctly follows the TRL equation?
Here this matlab code
clc;
clear;
% ===== Constants =====
c = 3e8; % Speed of light (m/s)
d = 2.62e-3; % Thickness in meters (example: 2.62 mm)
% ——————- Ask user to select Excel file ——————-
[filename, pathname] = uigetfile(‘*.xlsx’, ‘Select your S-parameter Excel file’);
if isequal(filename,0)
error(‘No file selected. Exiting…’);
end
filepath = fullfile(pathname, filename);
% ===== Read data from Excel =====
% Make sure your Excel file has columns: frequency(Hz), e’, e”, u’, u”
data = readmatrix(filepath); % Reads all numeric data
f = data(:,1); % Frequency in Hz
ep_real = data(:,2); % e’
ep_imag = data(:,3); % e”
mu_real = data(:,4); % u’
mu_imag = data(:,5); % u”
% ===== Complex parameters =====
eps_r = ep_real – 1i*ep_imag;
mu_r = mu_real – 1i*mu_imag;
% ===== Input impedance calculation =====
Zin = sqrt(mu_r ./ eps_r) .* tanh(-1i .* (2*pi.*f.*d./c) .* sqrt(mu_r .* eps_r));
% ===== Reflection Loss =====
RL = 20*log10(abs((Zin – 1) ./ (Zin + 1)));
% ===== Reflection coefficient =====
Gamma = abs((Zin – 1) ./ (Zin + 1));
% ===== Absorption percentage =====
Absorption = (1 – Gamma.^2) * 100;
% ===== Display results =====
Result = table(f, RL, Absorption)
% ===== Plot RL =====
figure
plot(f/1e9, RL,’LineWidth’,2)
xlabel(‘Frequency (GHz)’)
ylabel(‘Reflection Loss (dB)’)
title(‘Reflection Loss vs Frequency’)
grid onThe image contains the Transmission Line (TRL) equation. I am trying to develop a MATLAB code that matches this equation accurately. However, I need to verify that the implementation is consistent with the mathematical expression shown in the image.
Could you please review it and help ensure that the MATLAB code correctly follows the TRL equation?
Here this matlab code
clc;
clear;
% ===== Constants =====
c = 3e8; % Speed of light (m/s)
d = 2.62e-3; % Thickness in meters (example: 2.62 mm)
% ——————- Ask user to select Excel file ——————-
[filename, pathname] = uigetfile(‘*.xlsx’, ‘Select your S-parameter Excel file’);
if isequal(filename,0)
error(‘No file selected. Exiting…’);
end
filepath = fullfile(pathname, filename);
% ===== Read data from Excel =====
% Make sure your Excel file has columns: frequency(Hz), e’, e”, u’, u”
data = readmatrix(filepath); % Reads all numeric data
f = data(:,1); % Frequency in Hz
ep_real = data(:,2); % e’
ep_imag = data(:,3); % e”
mu_real = data(:,4); % u’
mu_imag = data(:,5); % u”
% ===== Complex parameters =====
eps_r = ep_real – 1i*ep_imag;
mu_r = mu_real – 1i*mu_imag;
% ===== Input impedance calculation =====
Zin = sqrt(mu_r ./ eps_r) .* tanh(-1i .* (2*pi.*f.*d./c) .* sqrt(mu_r .* eps_r));
% ===== Reflection Loss =====
RL = 20*log10(abs((Zin – 1) ./ (Zin + 1)));
% ===== Reflection coefficient =====
Gamma = abs((Zin – 1) ./ (Zin + 1));
% ===== Absorption percentage =====
Absorption = (1 – Gamma.^2) * 100;
% ===== Display results =====
Result = table(f, RL, Absorption)
% ===== Plot RL =====
figure
plot(f/1e9, RL,’LineWidth’,2)
xlabel(‘Frequency (GHz)’)
ylabel(‘Reflection Loss (dB)’)
title(‘Reflection Loss vs Frequency’)
grid on The image contains the Transmission Line (TRL) equation. I am trying to develop a MATLAB code that matches this equation accurately. However, I need to verify that the implementation is consistent with the mathematical expression shown in the image.
Could you please review it and help ensure that the MATLAB code correctly follows the TRL equation?
Here this matlab code
clc;
clear;
% ===== Constants =====
c = 3e8; % Speed of light (m/s)
d = 2.62e-3; % Thickness in meters (example: 2.62 mm)
% ——————- Ask user to select Excel file ——————-
[filename, pathname] = uigetfile(‘*.xlsx’, ‘Select your S-parameter Excel file’);
if isequal(filename,0)
error(‘No file selected. Exiting…’);
end
filepath = fullfile(pathname, filename);
% ===== Read data from Excel =====
% Make sure your Excel file has columns: frequency(Hz), e’, e”, u’, u”
data = readmatrix(filepath); % Reads all numeric data
f = data(:,1); % Frequency in Hz
ep_real = data(:,2); % e’
ep_imag = data(:,3); % e”
mu_real = data(:,4); % u’
mu_imag = data(:,5); % u”
% ===== Complex parameters =====
eps_r = ep_real – 1i*ep_imag;
mu_r = mu_real – 1i*mu_imag;
% ===== Input impedance calculation =====
Zin = sqrt(mu_r ./ eps_r) .* tanh(-1i .* (2*pi.*f.*d./c) .* sqrt(mu_r .* eps_r));
% ===== Reflection Loss =====
RL = 20*log10(abs((Zin – 1) ./ (Zin + 1)));
% ===== Reflection coefficient =====
Gamma = abs((Zin – 1) ./ (Zin + 1));
% ===== Absorption percentage =====
Absorption = (1 – Gamma.^2) * 100;
% ===== Display results =====
Result = table(f, RL, Absorption)
% ===== Plot RL =====
figure
plot(f/1e9, RL,’LineWidth’,2)
xlabel(‘Frequency (GHz)’)
ylabel(‘Reflection Loss (dB)’)
title(‘Reflection Loss vs Frequency’)
grid on transmission line theory trl equation matlab ma MATLAB Answers — New Questions









