Category: Matlab
Category Archives: Matlab
How to create line connects between two semi circles?
% Define parameters of the arc.
xCenter = 2;
yCenter = 1;
radius = -5;
% Define the angle theta as going from 30 to 150 degrees in 100 steps.
theta = linspace(10, 170, 100);
% Define x and y using "Degrees" version of sin and cos.
x = radius * cosd(theta) + xCenter;
y = radius * sind(theta) + yCenter;
% Now plot the points.
plot(x, y, ‘b-‘, ‘LineWidth’, 2);
axis equal;
grid on;
I figured out how to make the down semi circle and the upper one but I couldn’t know how to make the connecting line of the two semi circles to get the tooth profile as I am doing try and error to make development of arc tooth% Define parameters of the arc.
xCenter = 2;
yCenter = 1;
radius = -5;
% Define the angle theta as going from 30 to 150 degrees in 100 steps.
theta = linspace(10, 170, 100);
% Define x and y using "Degrees" version of sin and cos.
x = radius * cosd(theta) + xCenter;
y = radius * sind(theta) + yCenter;
% Now plot the points.
plot(x, y, ‘b-‘, ‘LineWidth’, 2);
axis equal;
grid on;
I figured out how to make the down semi circle and the upper one but I couldn’t know how to make the connecting line of the two semi circles to get the tooth profile as I am doing try and error to make development of arc tooth % Define parameters of the arc.
xCenter = 2;
yCenter = 1;
radius = -5;
% Define the angle theta as going from 30 to 150 degrees in 100 steps.
theta = linspace(10, 170, 100);
% Define x and y using "Degrees" version of sin and cos.
x = radius * cosd(theta) + xCenter;
y = radius * sind(theta) + yCenter;
% Now plot the points.
plot(x, y, ‘b-‘, ‘LineWidth’, 2);
axis equal;
grid on;
I figured out how to make the down semi circle and the upper one but I couldn’t know how to make the connecting line of the two semi circles to get the tooth profile as I am doing try and error to make development of arc tooth gears, for loop, mesh, mathematics MATLAB Answers — New Questions
eigs with complex hermitian matrix, should I set opts.issym to 1?
If the matrix is real and symmetric, I guess it is safe to set opts.issym = 1.
But what if the matrix is complex and hermitian?If the matrix is real and symmetric, I guess it is safe to set opts.issym = 1.
But what if the matrix is complex and hermitian? If the matrix is real and symmetric, I guess it is safe to set opts.issym = 1.
But what if the matrix is complex and hermitian? eigs MATLAB Answers — New Questions
Sort Table Variable with Cell Arrays
So I have a table being printed out in AppDesigner and I’d like to sort it based on the alphabetical order of the parameters in the first column. I’ve tried using sortrows but I get the following error:
An error occurred when sorting rows of the variable ‘t2’, whose type is ‘cell’.
Caused by:
Cell elements must be character arrays.
Without sorting anything the first few lines of the table so far look like this, with the cells in blue actually being a single column (as if it was merged like in an Excel sheet):
For coding I’ve done the following:
t1 = {‘Log Name’;’Parameter’;’Distance (m)’;’RPM’;’Speed (km/h)’;’Lat. Accel. (G)’};
t2 = [{‘ ‘ id_1 ‘ ‘};{‘Min Value’ ‘Max Value’ ‘Avg/Single Value’};{‘-‘ ‘-‘ max(dist_1)};{min(RPM_1) max(RPM_1) mean(RPM_1,’omitnan’)};…
{min(v_front_1) max(v_front_1) mean(v_front_1,’omitnan’)};{min(ay_1) max(ay_1) mean(ay_1,’omitnan’)}];
t = table(t1,t2);
I guess it has something to do with the fact that I’m using cell arrays (which I don’t fully understand) to get that "merged cell" look like in Excel but I couldn’t find a better way to do it. Thanks in advance.So I have a table being printed out in AppDesigner and I’d like to sort it based on the alphabetical order of the parameters in the first column. I’ve tried using sortrows but I get the following error:
An error occurred when sorting rows of the variable ‘t2’, whose type is ‘cell’.
Caused by:
Cell elements must be character arrays.
Without sorting anything the first few lines of the table so far look like this, with the cells in blue actually being a single column (as if it was merged like in an Excel sheet):
For coding I’ve done the following:
t1 = {‘Log Name’;’Parameter’;’Distance (m)’;’RPM’;’Speed (km/h)’;’Lat. Accel. (G)’};
t2 = [{‘ ‘ id_1 ‘ ‘};{‘Min Value’ ‘Max Value’ ‘Avg/Single Value’};{‘-‘ ‘-‘ max(dist_1)};{min(RPM_1) max(RPM_1) mean(RPM_1,’omitnan’)};…
{min(v_front_1) max(v_front_1) mean(v_front_1,’omitnan’)};{min(ay_1) max(ay_1) mean(ay_1,’omitnan’)}];
t = table(t1,t2);
I guess it has something to do with the fact that I’m using cell arrays (which I don’t fully understand) to get that "merged cell" look like in Excel but I couldn’t find a better way to do it. Thanks in advance. So I have a table being printed out in AppDesigner and I’d like to sort it based on the alphabetical order of the parameters in the first column. I’ve tried using sortrows but I get the following error:
An error occurred when sorting rows of the variable ‘t2’, whose type is ‘cell’.
Caused by:
Cell elements must be character arrays.
Without sorting anything the first few lines of the table so far look like this, with the cells in blue actually being a single column (as if it was merged like in an Excel sheet):
For coding I’ve done the following:
t1 = {‘Log Name’;’Parameter’;’Distance (m)’;’RPM’;’Speed (km/h)’;’Lat. Accel. (G)’};
t2 = [{‘ ‘ id_1 ‘ ‘};{‘Min Value’ ‘Max Value’ ‘Avg/Single Value’};{‘-‘ ‘-‘ max(dist_1)};{min(RPM_1) max(RPM_1) mean(RPM_1,’omitnan’)};…
{min(v_front_1) max(v_front_1) mean(v_front_1,’omitnan’)};{min(ay_1) max(ay_1) mean(ay_1,’omitnan’)}];
t = table(t1,t2);
I guess it has something to do with the fact that I’m using cell arrays (which I don’t fully understand) to get that "merged cell" look like in Excel but I couldn’t find a better way to do it. Thanks in advance. sorting, table MATLAB Answers — New Questions
How to linearly vary the amplitude and frequency in a 3 phase voltage source block with time?
I am working with the ‘Three-Phase Programmable Voltage Source’ block in simulink and I want to linearly vary both amplitude and frequency of the source with respect to simulation time. The exact functions I want are something like:
Amplitude = 5.5 + 10*t Volts (for 0<t<10) and 105.5 (for t>10)
Frequency = 5 + 8*t Hertz (for 0<t<10) and 85 (for t>10)
Where t is simulation time in seconds
How should I go about doing this? I am a novice so any help is appreciated.I am working with the ‘Three-Phase Programmable Voltage Source’ block in simulink and I want to linearly vary both amplitude and frequency of the source with respect to simulation time. The exact functions I want are something like:
Amplitude = 5.5 + 10*t Volts (for 0<t<10) and 105.5 (for t>10)
Frequency = 5 + 8*t Hertz (for 0<t<10) and 85 (for t>10)
Where t is simulation time in seconds
How should I go about doing this? I am a novice so any help is appreciated. I am working with the ‘Three-Phase Programmable Voltage Source’ block in simulink and I want to linearly vary both amplitude and frequency of the source with respect to simulation time. The exact functions I want are something like:
Amplitude = 5.5 + 10*t Volts (for 0<t<10) and 105.5 (for t>10)
Frequency = 5 + 8*t Hertz (for 0<t<10) and 85 (for t>10)
Where t is simulation time in seconds
How should I go about doing this? I am a novice so any help is appreciated. varying parameters wrt time, 3 phase voltage source MATLAB Answers — New Questions
Getting arrow key presses in code without any figures
Is there a way to get key presses, including arrow keys, in an m script which does not produce or need figures?
I have browsed through mulltple entries from the MATLAB community pages but all of the m files involve figures. I do not want or need graphical input, just a user interaction with the keyboard. I do not want to use simulink. Just a plain m file.
Please give a detailed answer, I am unfamiliar with callbacks and find them very confusing. If this does not require a callback (after all no figure is involved), so much the better.
thanksIs there a way to get key presses, including arrow keys, in an m script which does not produce or need figures?
I have browsed through mulltple entries from the MATLAB community pages but all of the m files involve figures. I do not want or need graphical input, just a user interaction with the keyboard. I do not want to use simulink. Just a plain m file.
Please give a detailed answer, I am unfamiliar with callbacks and find them very confusing. If this does not require a callback (after all no figure is involved), so much the better.
thanks Is there a way to get key presses, including arrow keys, in an m script which does not produce or need figures?
I have browsed through mulltple entries from the MATLAB community pages but all of the m files involve figures. I do not want or need graphical input, just a user interaction with the keyboard. I do not want to use simulink. Just a plain m file.
Please give a detailed answer, I am unfamiliar with callbacks and find them very confusing. If this does not require a callback (after all no figure is involved), so much the better.
thanks keypress MATLAB Answers — New Questions
Any other adaptor class instead of uavIMU that reads also magnetometer?
Is there any other adaptor class instead of uavIMU that reads also magnetometer in addition to accelerometer and gyro.
How could we parameterize the sensors inside the adaptor, to fix measurement range or add some noise… etcIs there any other adaptor class instead of uavIMU that reads also magnetometer in addition to accelerometer and gyro.
How could we parameterize the sensors inside the adaptor, to fix measurement range or add some noise… etc Is there any other adaptor class instead of uavIMU that reads also magnetometer in addition to accelerometer and gyro.
How could we parameterize the sensors inside the adaptor, to fix measurement range or add some noise… etc uavimu, magnetometer, add noise MATLAB Answers — New Questions
Unrecognized function or variable ‘chromagram_IF’.
C = chromagram_IF(audio_data,sample_rate,cfftlen);
i want to plot chroma features for an audio file, to detect musical notes for it. Here, specifically, I’m getting the error:
Unrecognized function or variable ‘chromagram_IF’.
Anybody know, what can i do that for that?
[audio_data, sample_rate] = audioread(file_path);
% Read an audio waveform
% Calculate the chroma matrix. Use a long FFT to discriminate
% spectral lines as well as possible (2048 is the default value)
cfftlen=2048;
C = chromagram_IF(audio_data,sample_rate,cfftlen);
% The frame advance is always one quarter of the FFT length. Thus,
% the columns of C are at timebase of fftlen/4/sr
tt = (1:size(C,2))*cfftlen/4/sample_rate;
% Plot spectrogram using a shorter window
subplot(311)
sfftlen = 512;
specgram(audio_data,sfftlen,sample_rate);
% Always use a 60 dB colormap range
clim(max(clim)+[-60 0])
% .. and look only at the bottom 4 kHz of spectrum
axis([0 length(d)/sample_rate 0 4000])
title(‘Original Sound’)
% Now the chromagram, also on a dB magnitude scale
subplot(312)
imagesc(tt,1:12,20*log10(C+eps));
axis xy
clim(max(clim)+[-60 0])
title(‘Chromagram’)C = chromagram_IF(audio_data,sample_rate,cfftlen);
i want to plot chroma features for an audio file, to detect musical notes for it. Here, specifically, I’m getting the error:
Unrecognized function or variable ‘chromagram_IF’.
Anybody know, what can i do that for that?
[audio_data, sample_rate] = audioread(file_path);
% Read an audio waveform
% Calculate the chroma matrix. Use a long FFT to discriminate
% spectral lines as well as possible (2048 is the default value)
cfftlen=2048;
C = chromagram_IF(audio_data,sample_rate,cfftlen);
% The frame advance is always one quarter of the FFT length. Thus,
% the columns of C are at timebase of fftlen/4/sr
tt = (1:size(C,2))*cfftlen/4/sample_rate;
% Plot spectrogram using a shorter window
subplot(311)
sfftlen = 512;
specgram(audio_data,sfftlen,sample_rate);
% Always use a 60 dB colormap range
clim(max(clim)+[-60 0])
% .. and look only at the bottom 4 kHz of spectrum
axis([0 length(d)/sample_rate 0 4000])
title(‘Original Sound’)
% Now the chromagram, also on a dB magnitude scale
subplot(312)
imagesc(tt,1:12,20*log10(C+eps));
axis xy
clim(max(clim)+[-60 0])
title(‘Chromagram’) C = chromagram_IF(audio_data,sample_rate,cfftlen);
i want to plot chroma features for an audio file, to detect musical notes for it. Here, specifically, I’m getting the error:
Unrecognized function or variable ‘chromagram_IF’.
Anybody know, what can i do that for that?
[audio_data, sample_rate] = audioread(file_path);
% Read an audio waveform
% Calculate the chroma matrix. Use a long FFT to discriminate
% spectral lines as well as possible (2048 is the default value)
cfftlen=2048;
C = chromagram_IF(audio_data,sample_rate,cfftlen);
% The frame advance is always one quarter of the FFT length. Thus,
% the columns of C are at timebase of fftlen/4/sr
tt = (1:size(C,2))*cfftlen/4/sample_rate;
% Plot spectrogram using a shorter window
subplot(311)
sfftlen = 512;
specgram(audio_data,sfftlen,sample_rate);
% Always use a 60 dB colormap range
clim(max(clim)+[-60 0])
% .. and look only at the bottom 4 kHz of spectrum
axis([0 length(d)/sample_rate 0 4000])
title(‘Original Sound’)
% Now the chromagram, also on a dB magnitude scale
subplot(312)
imagesc(tt,1:12,20*log10(C+eps));
axis xy
clim(max(clim)+[-60 0])
title(‘Chromagram’) chromotography, audio MATLAB Answers — New Questions
Calculation of Electric Field for the given two point charges.
There are two point charges 10nC at (1, 0, 2) and 5nC at (-2, 0, 3).
Calculate E at (1,3,2).
how to write matlab?There are two point charges 10nC at (1, 0, 2) and 5nC at (-2, 0, 3).
Calculate E at (1,3,2).
how to write matlab? There are two point charges 10nC at (1, 0, 2) and 5nC at (-2, 0, 3).
Calculate E at (1,3,2).
how to write matlab? electric field MATLAB Answers — New Questions
Is there a Matlab equivalent to the tsboot function in R?
I am working with time series data and different functions developed in R and Matlab. I was wondering if there was a similar MATLAB function that develops similar results as the tsboot() function in R.
I’ve reviewed https://www.spg.tu-darmstadt.de/res/dl/bootstraptoolboxformatlab/bootstrapmatlabtoolbox.en.jsp and it is still not clear how this would develop similar results.I am working with time series data and different functions developed in R and Matlab. I was wondering if there was a similar MATLAB function that develops similar results as the tsboot() function in R.
I’ve reviewed https://www.spg.tu-darmstadt.de/res/dl/bootstraptoolboxformatlab/bootstrapmatlabtoolbox.en.jsp and it is still not clear how this would develop similar results. I am working with time series data and different functions developed in R and Matlab. I was wondering if there was a similar MATLAB function that develops similar results as the tsboot() function in R.
I’ve reviewed https://www.spg.tu-darmstadt.de/res/dl/bootstraptoolboxformatlab/bootstrapmatlabtoolbox.en.jsp and it is still not clear how this would develop similar results. bootstrap, time series, block bootstrap MATLAB Answers — New Questions
Help Needed with Simulating PV Module in MATLAB/Simulink
Dear MATLAB Community,
I hope this message finds you well. I’m currently working on simulating the output of a photovoltaic (PV) module based on irradiance and temperature data. Specifically, I have two variables:
irr: A 1×1373798 double representing irradiance data for 16 days.
pvt: A 1×1373798 double representing temperature data for the same 16 days.
However, when attempting to execute the simulation in MATLAB/Simulink, I encountered the following error message:
——————————————————————————————————————————————————————————————
Error in port widths or dimensions. ‘Output Port 1’ of ‘PV_RealTime/PV Module 3/Diode Rsh/Add1’ has 1373797 elements. This port does not accept the dimensions (or orientation) specified by the output signal.
Component:Simulink | Category:Model error
Error in port widths or dimensions. Invalid dimension has been specified for ‘Input Port 1’ of ‘PV_RealTime/PV Module 3/Diode Rsh/Transfer Fcn’.
Component:Simulink | Category:Model error
——————————————————————————————————————————————————————————————
I believe this error is related to a dimension mismatch, but I’m unsure how to resolve it. Could someone please provide guidance or suggestions on how to address this issue? Any insights or assistance would be greatly appreciated.
Thank you in advance for your help!
Best regards,Dear MATLAB Community,
I hope this message finds you well. I’m currently working on simulating the output of a photovoltaic (PV) module based on irradiance and temperature data. Specifically, I have two variables:
irr: A 1×1373798 double representing irradiance data for 16 days.
pvt: A 1×1373798 double representing temperature data for the same 16 days.
However, when attempting to execute the simulation in MATLAB/Simulink, I encountered the following error message:
——————————————————————————————————————————————————————————————
Error in port widths or dimensions. ‘Output Port 1’ of ‘PV_RealTime/PV Module 3/Diode Rsh/Add1’ has 1373797 elements. This port does not accept the dimensions (or orientation) specified by the output signal.
Component:Simulink | Category:Model error
Error in port widths or dimensions. Invalid dimension has been specified for ‘Input Port 1’ of ‘PV_RealTime/PV Module 3/Diode Rsh/Transfer Fcn’.
Component:Simulink | Category:Model error
——————————————————————————————————————————————————————————————
I believe this error is related to a dimension mismatch, but I’m unsure how to resolve it. Could someone please provide guidance or suggestions on how to address this issue? Any insights or assistance would be greatly appreciated.
Thank you in advance for your help!
Best regards, Dear MATLAB Community,
I hope this message finds you well. I’m currently working on simulating the output of a photovoltaic (PV) module based on irradiance and temperature data. Specifically, I have two variables:
irr: A 1×1373798 double representing irradiance data for 16 days.
pvt: A 1×1373798 double representing temperature data for the same 16 days.
However, when attempting to execute the simulation in MATLAB/Simulink, I encountered the following error message:
——————————————————————————————————————————————————————————————
Error in port widths or dimensions. ‘Output Port 1’ of ‘PV_RealTime/PV Module 3/Diode Rsh/Add1’ has 1373797 elements. This port does not accept the dimensions (or orientation) specified by the output signal.
Component:Simulink | Category:Model error
Error in port widths or dimensions. Invalid dimension has been specified for ‘Input Port 1’ of ‘PV_RealTime/PV Module 3/Diode Rsh/Transfer Fcn’.
Component:Simulink | Category:Model error
——————————————————————————————————————————————————————————————
I believe this error is related to a dimension mismatch, but I’m unsure how to resolve it. Could someone please provide guidance or suggestions on how to address this issue? Any insights or assistance would be greatly appreciated.
Thank you in advance for your help!
Best regards, #matlab #simulink #pvmodule #simulationerror #dime MATLAB Answers — New Questions
Cross-section (Need help to correct the code or modify it )
Dear all
I need to correct or modify the following code to give the attached figure: clc
close all;
clear;
% Define the given arrays
x1 =[0, 1, 2, 3, 3.7];
z1 =[6, 6, 6, 6, 6];
x2 =[4.1, 5, 6, 7, 8, 9];
z2 =[4, 4, 4, 4, 4, 4];
x3 =[9, 10, 10, 11,12, 13, 14, 15, 16, 16.4];
z3 =[6, 6, 6, 6, 6, 6, 6, 6, 6, 6];
x4 =[15.3, 16, 17, 18, 19];
z4 =[3, 3, 3, 3, 3];
x =[x1,x2,x3,x4];
z =[z1,z2,z3,z4];
%x = [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21];
%z = [2 2 2 3 3 3 3 3 3 3 4 4 4 4 4 4 1 1 1 1 1 1];
% Find sudden changes in depth
sudden_changes = diff(z);
% Find indices where sudden changes occur
fault_indices = find(sudden_changes ~= 0) + 1;
% Initialize variables to store fault information
fault_locations = [];
fault_angles = [];
fault_types = {};
% Plot the top of the rock formation
plot(x, z, ‘-o’);
hold on;
grid on;
% Earth’s surface
earth_surface = zeros(size(x));
% Plot fault lines and gather fault information
for i = 1:length(fault_indices)
idx = fault_indices(i);
plot([x(idx-1), x(idx)], [z(idx-1), z(idx)], ‘r–‘);
% Calculate intersection point with Earth’s surface
intersection_x = x(idx-1) – z(idx-1) * (x(idx) – x(idx-1)) / (z(idx) – z(idx-1));
plot(intersection_x, 0, ‘ro’); % Plot intersection point
set(gca, ‘YDir’, ‘reverse’);
% Calculate dip angle using the tan-rule
dip_angle = atand((z(idx) – z(idx-1)) / (x(idx) – x(idx-1)));
% Determine fault type
if dip_angle <= 90
fault_type = ‘Normal’;
plot(intersection_x, 0, ‘go’); % Plot normal fault intersection point
elseif dip_angle > 90
fault_type = ‘Reverse’;
plot(intersection_x, 0, ‘mo’); % Plot reverse fault intersection point
else
fault_type = ‘Strike-Slip’;
end
% Store fault information
fault_locations = [fault_locations; intersection_x];
fault_angles = [fault_angles; dip_angle];
fault_types{end+1} = fault_type;
end
% Display fault information in a table
if isempty(fault_indices)
% Display a message if there are no faults
disp(‘No fault lines detected.’);
else
% Display fault information in a table
T = table(fault_locations, fault_angles, fault_types’, …
‘VariableNames’, {‘Location’, ‘Angle’, ‘Type’});
disp(T);
endDear all
I need to correct or modify the following code to give the attached figure: clc
close all;
clear;
% Define the given arrays
x1 =[0, 1, 2, 3, 3.7];
z1 =[6, 6, 6, 6, 6];
x2 =[4.1, 5, 6, 7, 8, 9];
z2 =[4, 4, 4, 4, 4, 4];
x3 =[9, 10, 10, 11,12, 13, 14, 15, 16, 16.4];
z3 =[6, 6, 6, 6, 6, 6, 6, 6, 6, 6];
x4 =[15.3, 16, 17, 18, 19];
z4 =[3, 3, 3, 3, 3];
x =[x1,x2,x3,x4];
z =[z1,z2,z3,z4];
%x = [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21];
%z = [2 2 2 3 3 3 3 3 3 3 4 4 4 4 4 4 1 1 1 1 1 1];
% Find sudden changes in depth
sudden_changes = diff(z);
% Find indices where sudden changes occur
fault_indices = find(sudden_changes ~= 0) + 1;
% Initialize variables to store fault information
fault_locations = [];
fault_angles = [];
fault_types = {};
% Plot the top of the rock formation
plot(x, z, ‘-o’);
hold on;
grid on;
% Earth’s surface
earth_surface = zeros(size(x));
% Plot fault lines and gather fault information
for i = 1:length(fault_indices)
idx = fault_indices(i);
plot([x(idx-1), x(idx)], [z(idx-1), z(idx)], ‘r–‘);
% Calculate intersection point with Earth’s surface
intersection_x = x(idx-1) – z(idx-1) * (x(idx) – x(idx-1)) / (z(idx) – z(idx-1));
plot(intersection_x, 0, ‘ro’); % Plot intersection point
set(gca, ‘YDir’, ‘reverse’);
% Calculate dip angle using the tan-rule
dip_angle = atand((z(idx) – z(idx-1)) / (x(idx) – x(idx-1)));
% Determine fault type
if dip_angle <= 90
fault_type = ‘Normal’;
plot(intersection_x, 0, ‘go’); % Plot normal fault intersection point
elseif dip_angle > 90
fault_type = ‘Reverse’;
plot(intersection_x, 0, ‘mo’); % Plot reverse fault intersection point
else
fault_type = ‘Strike-Slip’;
end
% Store fault information
fault_locations = [fault_locations; intersection_x];
fault_angles = [fault_angles; dip_angle];
fault_types{end+1} = fault_type;
end
% Display fault information in a table
if isempty(fault_indices)
% Display a message if there are no faults
disp(‘No fault lines detected.’);
else
% Display fault information in a table
T = table(fault_locations, fault_angles, fault_types’, …
‘VariableNames’, {‘Location’, ‘Angle’, ‘Type’});
disp(T);
end Dear all
I need to correct or modify the following code to give the attached figure: clc
close all;
clear;
% Define the given arrays
x1 =[0, 1, 2, 3, 3.7];
z1 =[6, 6, 6, 6, 6];
x2 =[4.1, 5, 6, 7, 8, 9];
z2 =[4, 4, 4, 4, 4, 4];
x3 =[9, 10, 10, 11,12, 13, 14, 15, 16, 16.4];
z3 =[6, 6, 6, 6, 6, 6, 6, 6, 6, 6];
x4 =[15.3, 16, 17, 18, 19];
z4 =[3, 3, 3, 3, 3];
x =[x1,x2,x3,x4];
z =[z1,z2,z3,z4];
%x = [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21];
%z = [2 2 2 3 3 3 3 3 3 3 4 4 4 4 4 4 1 1 1 1 1 1];
% Find sudden changes in depth
sudden_changes = diff(z);
% Find indices where sudden changes occur
fault_indices = find(sudden_changes ~= 0) + 1;
% Initialize variables to store fault information
fault_locations = [];
fault_angles = [];
fault_types = {};
% Plot the top of the rock formation
plot(x, z, ‘-o’);
hold on;
grid on;
% Earth’s surface
earth_surface = zeros(size(x));
% Plot fault lines and gather fault information
for i = 1:length(fault_indices)
idx = fault_indices(i);
plot([x(idx-1), x(idx)], [z(idx-1), z(idx)], ‘r–‘);
% Calculate intersection point with Earth’s surface
intersection_x = x(idx-1) – z(idx-1) * (x(idx) – x(idx-1)) / (z(idx) – z(idx-1));
plot(intersection_x, 0, ‘ro’); % Plot intersection point
set(gca, ‘YDir’, ‘reverse’);
% Calculate dip angle using the tan-rule
dip_angle = atand((z(idx) – z(idx-1)) / (x(idx) – x(idx-1)));
% Determine fault type
if dip_angle <= 90
fault_type = ‘Normal’;
plot(intersection_x, 0, ‘go’); % Plot normal fault intersection point
elseif dip_angle > 90
fault_type = ‘Reverse’;
plot(intersection_x, 0, ‘mo’); % Plot reverse fault intersection point
else
fault_type = ‘Strike-Slip’;
end
% Store fault information
fault_locations = [fault_locations; intersection_x];
fault_angles = [fault_angles; dip_angle];
fault_types{end+1} = fault_type;
end
% Display fault information in a table
if isempty(fault_indices)
% Display a message if there are no faults
disp(‘No fault lines detected.’);
else
% Display fault information in a table
T = table(fault_locations, fault_angles, fault_types’, …
‘VariableNames’, {‘Location’, ‘Angle’, ‘Type’});
disp(T);
end cross-section, dip angle, location MATLAB Answers — New Questions
A question from an artical “Isocost Lines Describe the Cellular Economy of Genetic Circuits”
Here is the link of this artical’s supplementary information:
https://www.cell.com/cms/10.1016/j.bpj.2015.06.034/attachment/4346d19d-fad3-4cb8-87d3-8d4c7baa6cc9/mmc1.pdf
How they achieve this linear constraint, the alpha and beta?
I am new in math so if there are codes provived, I will be appreciated.Here is the link of this artical’s supplementary information:
https://www.cell.com/cms/10.1016/j.bpj.2015.06.034/attachment/4346d19d-fad3-4cb8-87d3-8d4c7baa6cc9/mmc1.pdf
How they achieve this linear constraint, the alpha and beta?
I am new in math so if there are codes provived, I will be appreciated. Here is the link of this artical’s supplementary information:
https://www.cell.com/cms/10.1016/j.bpj.2015.06.034/attachment/4346d19d-fad3-4cb8-87d3-8d4c7baa6cc9/mmc1.pdf
How they achieve this linear constraint, the alpha and beta?
I am new in math so if there are codes provived, I will be appreciated. computational biology MATLAB Answers — New Questions
How do I use the buffer function to operate real time on EEG signal files?
Hello, I’ve got a code where I detect signals through thresholding, but I’d like for the thresholding to reapply to the signal every 40 seconds or so if I enter a 5 minute signal. I’ve found buffering can help with this, but I am having some issues applying it. I want to segment the signal into 40 second segments (can be overlapping or non overlapping), however since the original signal (300 seconds) has been multiplied by the frequency 256, it is now 76800 values and I’m slightly confused. I am not sure which variables to alter, and the wiki example doesn’t seem to apply to my signal type. I help appreciate some help understanding how the function works and how to apply if possible.
eegsignal = (data_array2(710656:787456)); %signal to be inserted around 5 mins long
%contains non-seizure and then seizure
fs = 256;
frame_length = 40
signal_length = 300*256
sig = buffer(1:76800,40);
n = 5;
p = 1;
opt = -5;
z = [];
for i = 1:size(sig,2)
x = sig(:,i);
[y,z,oppt] = buffer([z;x],n,p,opt);
if i <= 4
disp(‘no seizure’)
end
opt = oppt;
endHello, I’ve got a code where I detect signals through thresholding, but I’d like for the thresholding to reapply to the signal every 40 seconds or so if I enter a 5 minute signal. I’ve found buffering can help with this, but I am having some issues applying it. I want to segment the signal into 40 second segments (can be overlapping or non overlapping), however since the original signal (300 seconds) has been multiplied by the frequency 256, it is now 76800 values and I’m slightly confused. I am not sure which variables to alter, and the wiki example doesn’t seem to apply to my signal type. I help appreciate some help understanding how the function works and how to apply if possible.
eegsignal = (data_array2(710656:787456)); %signal to be inserted around 5 mins long
%contains non-seizure and then seizure
fs = 256;
frame_length = 40
signal_length = 300*256
sig = buffer(1:76800,40);
n = 5;
p = 1;
opt = -5;
z = [];
for i = 1:size(sig,2)
x = sig(:,i);
[y,z,oppt] = buffer([z;x],n,p,opt);
if i <= 4
disp(‘no seizure’)
end
opt = oppt;
end Hello, I’ve got a code where I detect signals through thresholding, but I’d like for the thresholding to reapply to the signal every 40 seconds or so if I enter a 5 minute signal. I’ve found buffering can help with this, but I am having some issues applying it. I want to segment the signal into 40 second segments (can be overlapping or non overlapping), however since the original signal (300 seconds) has been multiplied by the frequency 256, it is now 76800 values and I’m slightly confused. I am not sure which variables to alter, and the wiki example doesn’t seem to apply to my signal type. I help appreciate some help understanding how the function works and how to apply if possible.
eegsignal = (data_array2(710656:787456)); %signal to be inserted around 5 mins long
%contains non-seizure and then seizure
fs = 256;
frame_length = 40
signal_length = 300*256
sig = buffer(1:76800,40);
n = 5;
p = 1;
opt = -5;
z = [];
for i = 1:size(sig,2)
x = sig(:,i);
[y,z,oppt] = buffer([z;x],n,p,opt);
if i <= 4
disp(‘no seizure’)
end
opt = oppt;
end buffer, real time, function, eeg, image segmentation MATLAB Answers — New Questions
High fluctuation in Q0 value for TD3 agent while training.
I am training a TD3 RL agent for pick and place robot. The reward function is, reward = exp(-E/d) where E is the total energy consumed where the trajectory is complete and d is the distance of the object from the end-effector. The training went smoothly while using DQN agent but it fails when DDPG, TD3 are used. What could be the reasion for this? I used the following code for agent creation.
obsInfo = rlNumericSpec([34 1]);
actInfo = rlNumericSpec([14 1], …
LowerLimit=-1, …
UpperLimit= 1);
env = rlFunctionEnv(obsInfo,actInfo,"KondoStepFunction","KondoResetFunction");
agent = rlTD3Agent(obsInfo,actInfo);I am training a TD3 RL agent for pick and place robot. The reward function is, reward = exp(-E/d) where E is the total energy consumed where the trajectory is complete and d is the distance of the object from the end-effector. The training went smoothly while using DQN agent but it fails when DDPG, TD3 are used. What could be the reasion for this? I used the following code for agent creation.
obsInfo = rlNumericSpec([34 1]);
actInfo = rlNumericSpec([14 1], …
LowerLimit=-1, …
UpperLimit= 1);
env = rlFunctionEnv(obsInfo,actInfo,"KondoStepFunction","KondoResetFunction");
agent = rlTD3Agent(obsInfo,actInfo); I am training a TD3 RL agent for pick and place robot. The reward function is, reward = exp(-E/d) where E is the total energy consumed where the trajectory is complete and d is the distance of the object from the end-effector. The training went smoothly while using DQN agent but it fails when DDPG, TD3 are used. What could be the reasion for this? I used the following code for agent creation.
obsInfo = rlNumericSpec([34 1]);
actInfo = rlNumericSpec([14 1], …
LowerLimit=-1, …
UpperLimit= 1);
env = rlFunctionEnv(obsInfo,actInfo,"KondoStepFunction","KondoResetFunction");
agent = rlTD3Agent(obsInfo,actInfo); #robotics, #reinforcement learning, #matlab MATLAB Answers — New Questions
Export Simulink Model as Standalone FMU – [FATAL][FMICAPI] Could not load the DLL: module not found. [FATAL][FMUCHK] Could not create the DLL loading mechanism(C-API) for CoSi
Hello everyone!
I exported a simulink model as a standalone FMU (FMI version 2.0). The model uses a variable step solver.
Re – Importing this FMU into simulink works quite fine, but I want to use it in python. My tool of choice is the "fmpy" library. When I want to simulate the model in python using simulate_fmu(‘NEWmodel2Export.fmu’), I get the following error message:
Exception: Failed to load shared library C:UsersjakobAppDataLocalTemptmpt98a7m_2binarieswin64NEWmodel2Export.dll. Could not find module ‘C:UsersjakobAppDataLocalTemptmpt98a7m_2binarieswin64NEWmodel2Export.dll’ (or one of its dependencies). Try using the full path with constructor syntax.
I also checked the FMU by using the FMUChecker 2.0.4. It returns the following (fatal) error messages, which could be dependent in my opinion:
[INFO][FMUCHK] No input data provided. In case of simulation initial values from FMU will be used.
[INFO][FMUCHK] Printing output file header
"time","h_Laufrad","mL"
[INFO][FMUCHK] Model identifier for CoSimulation: NEWmodel2Export
[INFO][FMILIB] Loading ‘win64’ binary with ‘default’ platform types
[FATAL][FMICAPI] Could not load the DLL: Das angegebene Modul wurde nicht gefunden.
[FATAL][FMUCHK] Could not create the DLL loading mechanism(C-API) for CoSimulation.
FMU check summary:
FMU reported:
0 warning(s) and error(s)
Checker reported:
0 Warning(s)
2 Error(s)
2 Fatal error(s) occurred during processing
I think that this might have something to do with the usage of the variable step solver.
Thank you very much in advance!Hello everyone!
I exported a simulink model as a standalone FMU (FMI version 2.0). The model uses a variable step solver.
Re – Importing this FMU into simulink works quite fine, but I want to use it in python. My tool of choice is the "fmpy" library. When I want to simulate the model in python using simulate_fmu(‘NEWmodel2Export.fmu’), I get the following error message:
Exception: Failed to load shared library C:UsersjakobAppDataLocalTemptmpt98a7m_2binarieswin64NEWmodel2Export.dll. Could not find module ‘C:UsersjakobAppDataLocalTemptmpt98a7m_2binarieswin64NEWmodel2Export.dll’ (or one of its dependencies). Try using the full path with constructor syntax.
I also checked the FMU by using the FMUChecker 2.0.4. It returns the following (fatal) error messages, which could be dependent in my opinion:
[INFO][FMUCHK] No input data provided. In case of simulation initial values from FMU will be used.
[INFO][FMUCHK] Printing output file header
"time","h_Laufrad","mL"
[INFO][FMUCHK] Model identifier for CoSimulation: NEWmodel2Export
[INFO][FMILIB] Loading ‘win64’ binary with ‘default’ platform types
[FATAL][FMICAPI] Could not load the DLL: Das angegebene Modul wurde nicht gefunden.
[FATAL][FMUCHK] Could not create the DLL loading mechanism(C-API) for CoSimulation.
FMU check summary:
FMU reported:
0 warning(s) and error(s)
Checker reported:
0 Warning(s)
2 Error(s)
2 Fatal error(s) occurred during processing
I think that this might have something to do with the usage of the variable step solver.
Thank you very much in advance! Hello everyone!
I exported a simulink model as a standalone FMU (FMI version 2.0). The model uses a variable step solver.
Re – Importing this FMU into simulink works quite fine, but I want to use it in python. My tool of choice is the "fmpy" library. When I want to simulate the model in python using simulate_fmu(‘NEWmodel2Export.fmu’), I get the following error message:
Exception: Failed to load shared library C:UsersjakobAppDataLocalTemptmpt98a7m_2binarieswin64NEWmodel2Export.dll. Could not find module ‘C:UsersjakobAppDataLocalTemptmpt98a7m_2binarieswin64NEWmodel2Export.dll’ (or one of its dependencies). Try using the full path with constructor syntax.
I also checked the FMU by using the FMUChecker 2.0.4. It returns the following (fatal) error messages, which could be dependent in my opinion:
[INFO][FMUCHK] No input data provided. In case of simulation initial values from FMU will be used.
[INFO][FMUCHK] Printing output file header
"time","h_Laufrad","mL"
[INFO][FMUCHK] Model identifier for CoSimulation: NEWmodel2Export
[INFO][FMILIB] Loading ‘win64’ binary with ‘default’ platform types
[FATAL][FMICAPI] Could not load the DLL: Das angegebene Modul wurde nicht gefunden.
[FATAL][FMUCHK] Could not create the DLL loading mechanism(C-API) for CoSimulation.
FMU check summary:
FMU reported:
0 warning(s) and error(s)
Checker reported:
0 Warning(s)
2 Error(s)
2 Fatal error(s) occurred during processing
I think that this might have something to do with the usage of the variable step solver.
Thank you very much in advance! standalone fmu, dll missing, variable step solver, could not create the dll loading mechanism(c-api), [fatal][fmicapi] could not load the dll: MATLAB Answers — New Questions
Invalid setting in ‘file/powergui’ for parameter ‘Value” caused by index position 1 exceeds array bounds. index must be not exceed 2.
Post Content Post Content discrete block MATLAB Answers — New Questions
Getting an error using writebmp (line 14) Expected X to be one of these types: logical, uint8, single, double
I am new to MATLAB and am getting the above error in my code. In my code, I read an altered (steganographic) image and extract a few bits from it. The embedding process went smoothly, but I am having some issues with the code’s extraction.
Here’s the code link https://drive.mathworks.com/sharing/5c7d84a6-d359-4856-9515-c637b9a7964dI am new to MATLAB and am getting the above error in my code. In my code, I read an altered (steganographic) image and extract a few bits from it. The embedding process went smoothly, but I am having some issues with the code’s extraction.
Here’s the code link https://drive.mathworks.com/sharing/5c7d84a6-d359-4856-9515-c637b9a7964d I am new to MATLAB and am getting the above error in my code. In my code, I read an altered (steganographic) image and extract a few bits from it. The embedding process went smoothly, but I am having some issues with the code’s extraction.
Here’s the code link https://drive.mathworks.com/sharing/5c7d84a6-d359-4856-9515-c637b9a7964d image processing, digital image processing, matlab code, matlab basics MATLAB Answers — New Questions
How to use measured variables in simscape multibody
I’m pretty new to Simscape Multibody and self-taught. I’m trying to create the model of a 2DOF RR articulated arm with gravity compensation through the use of cable and spring (not yet modeled because i have some prior issues).
I want to impose cable length constant (I don’t think there’s a simple action to do it) and to do so i’m measuring the wrap angles of spool and pulley, as you can see in the slx attached. The problem is that i have to run the program first with the subsystem commented out to create the variables’ WA_spool1 and WA_perno1, and then i can generate the two rigid transforms in the subsystem and measure cable length.
Is it possible to use those variables in real time inside the simscape program, considering also their time dependency, without exporting them first to the workspace?I’m pretty new to Simscape Multibody and self-taught. I’m trying to create the model of a 2DOF RR articulated arm with gravity compensation through the use of cable and spring (not yet modeled because i have some prior issues).
I want to impose cable length constant (I don’t think there’s a simple action to do it) and to do so i’m measuring the wrap angles of spool and pulley, as you can see in the slx attached. The problem is that i have to run the program first with the subsystem commented out to create the variables’ WA_spool1 and WA_perno1, and then i can generate the two rigid transforms in the subsystem and measure cable length.
Is it possible to use those variables in real time inside the simscape program, considering also their time dependency, without exporting them first to the workspace? I’m pretty new to Simscape Multibody and self-taught. I’m trying to create the model of a 2DOF RR articulated arm with gravity compensation through the use of cable and spring (not yet modeled because i have some prior issues).
I want to impose cable length constant (I don’t think there’s a simple action to do it) and to do so i’m measuring the wrap angles of spool and pulley, as you can see in the slx attached. The problem is that i have to run the program first with the subsystem commented out to create the variables’ WA_spool1 and WA_perno1, and then i can generate the two rigid transforms in the subsystem and measure cable length.
Is it possible to use those variables in real time inside the simscape program, considering also their time dependency, without exporting them first to the workspace? simscape, multibody MATLAB Answers — New Questions
Issues with script writing mixed text/numeric data to file as a table
Hello, I am new to MATLAB and need to use a user-defined function IPtoCK to convert a set of people’s height and weight in inches and pounds to centimeters and kilograms, respectively, but then write the resulting data as well as calculated BMIs and BMI categories (i.e. underweight, normal, overweight, obese) into a formatted table in a text file. My user defined function works well enough but the output written to BMI.txt is not formatted correctly with one decimal place for all numeric values as I need them to be, no matter how I specify. They also only export some of the height data in centimeters to the text document, and in a matrix that appears to be of inconsistent delimiters and dimensions(?). I decided to enter the category entries as character arrays rather than strings so that they are all 1×1 vector containers rather than string arrays of various sizes, but I am also unsure of how to write the character arrays into a column vector in order to concatenate it onto the table with the numeric values, or otherwise have it show up as the last column in BMI.txt. Any advice would be appreciated! Thank you!!
Here is what the code writes to BMI.txt:
Height(cm) Weight(kg) BMI Category
148.0 171.0 177.0162.0 169.0 173.0164.0 170.0 174.0161.0 178.0 181.0173.0 170.0 158.0175.0 158.0 186.0175.0 173.0 166.0148.0 158.0 174.0194.0 177.0 173.0165.0 171.0 180.0167.0 189.0 158.0166.0 171.0 150.0176.0 171.0 171.0178.0 180.0 178.0165.0 170.0 174.0157.0 160.0 166.0171.0 188.0 45.2 72.0 66.8 75.9 70.4 67.6 66.9 66.4 79.7 58.2 62.2 77.8 82.9 56.1 55.6 79.7 43.0 86.1 77.4 70.8 57.0 50.3 58.1 78.1 94.1 68.8 83.4 62.2 60.1 70.3 71.3 84.3 64.1 64.0 89.1 40.5 67.4 66.5 68.0 86.7 76.7 71.8 63.2 73.0 63.4 60.0 46.9 62.7 59.0 74.4 20.6 24.6 21.3 28.9 24.6 22.6 24.9 23.0 26.3 22.5 19.6 23.7 27.7 19.4 22.3 26.0 17.2 24.9 25.3 23.7 20.7 23.0 23.3 25.8 25.0 22.0 27.9 22.8 20.6 21.7 25.6 23.6 25.7 23.2 30.5 18.0 21.8 22.7 23.3 27.4 23.7 22.7 23.2 25.3 20.9 24.3 18.3 22.8 20.2 21.0
And here is my code:
IP=readmatrix(‘HeightWeightIP.txt’);
format shortG
INCHES=[IP(:,1)];
POUNDS=[IP(:,2)];
I=INCHES;
P=POUNDS;
[C,K]=IPtoCK(INCHES,POUNDS);
CENTIMETERS=C;
KILOGRAMS=K;
BMI=[KILOGRAMS./(0.01.*CENTIMETERS).^2];
for CK=[1:length(BMI)]
if BMI(CK)<18.5
Category="underweight";
elseif BMI(CK)>=18.5 & BMI(CK)<25
Category="normal";
elseif BMI(CK)>=25 & BMI(CK)<30
Category="overweight";
else
Category="obese";
end
BMICAT=[BMI(CK)]
end
fid=fopen(‘BMI.txt’,’w’);
fprintf(fid, ‘Height(cm) Weight(kg) BMI Categoryn’)
fprintf(fid, ‘%5.1f %4.1f %4.1f’, CENTIMETERS, KILOGRAMS, BMI)Hello, I am new to MATLAB and need to use a user-defined function IPtoCK to convert a set of people’s height and weight in inches and pounds to centimeters and kilograms, respectively, but then write the resulting data as well as calculated BMIs and BMI categories (i.e. underweight, normal, overweight, obese) into a formatted table in a text file. My user defined function works well enough but the output written to BMI.txt is not formatted correctly with one decimal place for all numeric values as I need them to be, no matter how I specify. They also only export some of the height data in centimeters to the text document, and in a matrix that appears to be of inconsistent delimiters and dimensions(?). I decided to enter the category entries as character arrays rather than strings so that they are all 1×1 vector containers rather than string arrays of various sizes, but I am also unsure of how to write the character arrays into a column vector in order to concatenate it onto the table with the numeric values, or otherwise have it show up as the last column in BMI.txt. Any advice would be appreciated! Thank you!!
Here is what the code writes to BMI.txt:
Height(cm) Weight(kg) BMI Category
148.0 171.0 177.0162.0 169.0 173.0164.0 170.0 174.0161.0 178.0 181.0173.0 170.0 158.0175.0 158.0 186.0175.0 173.0 166.0148.0 158.0 174.0194.0 177.0 173.0165.0 171.0 180.0167.0 189.0 158.0166.0 171.0 150.0176.0 171.0 171.0178.0 180.0 178.0165.0 170.0 174.0157.0 160.0 166.0171.0 188.0 45.2 72.0 66.8 75.9 70.4 67.6 66.9 66.4 79.7 58.2 62.2 77.8 82.9 56.1 55.6 79.7 43.0 86.1 77.4 70.8 57.0 50.3 58.1 78.1 94.1 68.8 83.4 62.2 60.1 70.3 71.3 84.3 64.1 64.0 89.1 40.5 67.4 66.5 68.0 86.7 76.7 71.8 63.2 73.0 63.4 60.0 46.9 62.7 59.0 74.4 20.6 24.6 21.3 28.9 24.6 22.6 24.9 23.0 26.3 22.5 19.6 23.7 27.7 19.4 22.3 26.0 17.2 24.9 25.3 23.7 20.7 23.0 23.3 25.8 25.0 22.0 27.9 22.8 20.6 21.7 25.6 23.6 25.7 23.2 30.5 18.0 21.8 22.7 23.3 27.4 23.7 22.7 23.2 25.3 20.9 24.3 18.3 22.8 20.2 21.0
And here is my code:
IP=readmatrix(‘HeightWeightIP.txt’);
format shortG
INCHES=[IP(:,1)];
POUNDS=[IP(:,2)];
I=INCHES;
P=POUNDS;
[C,K]=IPtoCK(INCHES,POUNDS);
CENTIMETERS=C;
KILOGRAMS=K;
BMI=[KILOGRAMS./(0.01.*CENTIMETERS).^2];
for CK=[1:length(BMI)]
if BMI(CK)<18.5
Category="underweight";
elseif BMI(CK)>=18.5 & BMI(CK)<25
Category="normal";
elseif BMI(CK)>=25 & BMI(CK)<30
Category="overweight";
else
Category="obese";
end
BMICAT=[BMI(CK)]
end
fid=fopen(‘BMI.txt’,’w’);
fprintf(fid, ‘Height(cm) Weight(kg) BMI Categoryn’)
fprintf(fid, ‘%5.1f %4.1f %4.1f’, CENTIMETERS, KILOGRAMS, BMI) Hello, I am new to MATLAB and need to use a user-defined function IPtoCK to convert a set of people’s height and weight in inches and pounds to centimeters and kilograms, respectively, but then write the resulting data as well as calculated BMIs and BMI categories (i.e. underweight, normal, overweight, obese) into a formatted table in a text file. My user defined function works well enough but the output written to BMI.txt is not formatted correctly with one decimal place for all numeric values as I need them to be, no matter how I specify. They also only export some of the height data in centimeters to the text document, and in a matrix that appears to be of inconsistent delimiters and dimensions(?). I decided to enter the category entries as character arrays rather than strings so that they are all 1×1 vector containers rather than string arrays of various sizes, but I am also unsure of how to write the character arrays into a column vector in order to concatenate it onto the table with the numeric values, or otherwise have it show up as the last column in BMI.txt. Any advice would be appreciated! Thank you!!
Here is what the code writes to BMI.txt:
Height(cm) Weight(kg) BMI Category
148.0 171.0 177.0162.0 169.0 173.0164.0 170.0 174.0161.0 178.0 181.0173.0 170.0 158.0175.0 158.0 186.0175.0 173.0 166.0148.0 158.0 174.0194.0 177.0 173.0165.0 171.0 180.0167.0 189.0 158.0166.0 171.0 150.0176.0 171.0 171.0178.0 180.0 178.0165.0 170.0 174.0157.0 160.0 166.0171.0 188.0 45.2 72.0 66.8 75.9 70.4 67.6 66.9 66.4 79.7 58.2 62.2 77.8 82.9 56.1 55.6 79.7 43.0 86.1 77.4 70.8 57.0 50.3 58.1 78.1 94.1 68.8 83.4 62.2 60.1 70.3 71.3 84.3 64.1 64.0 89.1 40.5 67.4 66.5 68.0 86.7 76.7 71.8 63.2 73.0 63.4 60.0 46.9 62.7 59.0 74.4 20.6 24.6 21.3 28.9 24.6 22.6 24.9 23.0 26.3 22.5 19.6 23.7 27.7 19.4 22.3 26.0 17.2 24.9 25.3 23.7 20.7 23.0 23.3 25.8 25.0 22.0 27.9 22.8 20.6 21.7 25.6 23.6 25.7 23.2 30.5 18.0 21.8 22.7 23.3 27.4 23.7 22.7 23.2 25.3 20.9 24.3 18.3 22.8 20.2 21.0
And here is my code:
IP=readmatrix(‘HeightWeightIP.txt’);
format shortG
INCHES=[IP(:,1)];
POUNDS=[IP(:,2)];
I=INCHES;
P=POUNDS;
[C,K]=IPtoCK(INCHES,POUNDS);
CENTIMETERS=C;
KILOGRAMS=K;
BMI=[KILOGRAMS./(0.01.*CENTIMETERS).^2];
for CK=[1:length(BMI)]
if BMI(CK)<18.5
Category="underweight";
elseif BMI(CK)>=18.5 & BMI(CK)<25
Category="normal";
elseif BMI(CK)>=25 & BMI(CK)<30
Category="overweight";
else
Category="obese";
end
BMICAT=[BMI(CK)]
end
fid=fopen(‘BMI.txt’,’w’);
fprintf(fid, ‘Height(cm) Weight(kg) BMI Categoryn’)
fprintf(fid, ‘%5.1f %4.1f %4.1f’, CENTIMETERS, KILOGRAMS, BMI) character arrays MATLAB Answers — New Questions
User-defined monthly loan payment function issues
Hello! I am trying to create a very simple user-defined function to calculate monthly payments on a loan, but I am unsure why my function is returning "0". I am sure it must be a silly formatting error, but I would appreciate any help pointing out my mistake! Thank you!
% amort returns monthly payment of a loan given the loan amount, annual interest
% rate, and length of loan
% P=loan amount
% r=annual interest rate (in percent)
% N=length of loan in years
function [M]=amort(P,r,N)
M=P*((r/1200)/(1-(1+(r/1200)))^((-12)*N))Hello! I am trying to create a very simple user-defined function to calculate monthly payments on a loan, but I am unsure why my function is returning "0". I am sure it must be a silly formatting error, but I would appreciate any help pointing out my mistake! Thank you!
% amort returns monthly payment of a loan given the loan amount, annual interest
% rate, and length of loan
% P=loan amount
% r=annual interest rate (in percent)
% N=length of loan in years
function [M]=amort(P,r,N)
M=P*((r/1200)/(1-(1+(r/1200)))^((-12)*N)) Hello! I am trying to create a very simple user-defined function to calculate monthly payments on a loan, but I am unsure why my function is returning "0". I am sure it must be a silly formatting error, but I would appreciate any help pointing out my mistake! Thank you!
% amort returns monthly payment of a loan given the loan amount, annual interest
% rate, and length of loan
% P=loan amount
% r=annual interest rate (in percent)
% N=length of loan in years
function [M]=amort(P,r,N)
M=P*((r/1200)/(1-(1+(r/1200)))^((-12)*N)) user-defined function MATLAB Answers — New Questions