Not showing lines and curves in the plot.

1 view (last 30 days)
Mark Cuanan
Mark Cuanan on 29 Jan 2024
Edited: Walter Roberson on 29 Jan 2024
Can someone check this script, why there is no lines/curves showin in my plot. Thank you
function [V_design, D_design] = bilinear_fit_capacity_curve_from_excel(filename)
% Bilinear curve fitting of capacity curve from Excel file according to FEMA guidelines
% filename - Name of the Excel file
% Read data from Excel file
data = readtable('your_excel_file.xlsx');
D_capacity__str = data(:, 1); % Displacement
V_capacity__str = data(:, 2); % Base shear
% Convert base_shear from strings to numeric format
V_capacity__numeric = str2double(V_capacity__str);
% Check for any conversion errors (NaNs)
conversion_errors = isnan(V_capacity__numeric);
if any(conversion_errors)
% Handle conversion errors (e.g., replace NaNs with appropriate values)
% For example, you can set NaNs to zero:
V_capacity__numeric(conversion_errors) = 0;
end
% Convert base_shear from strings to numeric format
D_capacity__numeric = str2double(D_capacity__str);
% Check for any conversion errors (NaNs)
conversion_errors = isnan(D_capacity__numeric);
if any(conversion_errors)
% Handle conversion errors (e.g., replace NaNs with appropriate values)
% For example, you can set NaNs to zero:
D_capacity_numeric(conversion_errors) = 0;
end
% Find the yield point
[V_y, idx_y] = max(V_capacity__numeric);
% Find the ultimate point
[V_ult, idx_ult] = min(V_capacity__numeric);
% Define the first segment slope
slope1 = (V_y - 0) / D_capacity_numeric(idx_y);
% Define the second segment slope
slope2 = (V_ult - V_y) / (D_capacity_numeric(idx_ult) - D_capacity_numeric(idx_y));
% Calculate the bilinearized curve
V_design = zeros(size(V_capacity__numeric));
D_design = zeros(size(D_capacity_numeric));
% First segment
V_design(1:idx_y) = slope1 * D_capacity_numeric(1:idx_y);
D_design(1:idx_y) = D_capacity_numeric(1:idx_y);
% Second segment
V_design(idx_y+1:end) = V_y + slope2 * (D_capacity_numeric(idx_y+1:end) - D_capacity_numeric(idx_y));
D_design(idx_y+1:end) = D_capacity_numeric(idx_y+1:end);
% Plot original and bilinearized capacity curves
figure;
plot(D_capacity_numeric, V_capacity__numeric, 'b-', 'LineWidth', 2);
hold on;
plot(D_design, V_design, 'r--', 'LineWidth', 2);
xlabel('Displacement');
ylabel('Base Shear (V)');
title('Capacity Curve Bilinear Fitting');
legend('Original Capacity Curve', 'Bilinearized Curve');
grid on;
hold off;
end

Answers (1)

Voss
Voss on 29 Jan 2024
Edited: Voss on 29 Jan 2024
(Using the xlsx file you shared in this question's thread.)
Use curly braces to access data from a table variable, as in:
D_capacity__str = data{:, 1}; % Displacement
V_capacity__str = data{:, 2}; % Base shear
If you use parentheses, then D_capacity__str and V_capacity__str are also tables (with one column each), and this line
V_capacity__numeric = str2double(V_capacity__str);
makes V_capacity__numeric a scalar NaN instead of a numeric (non-scalar) vector.
Also, you define the variable "D_capacity__numeric", but you refer to it as "D_capacity_numeric" (with one fewer underscore) almost everywhere else, so I changed it to "D_capacity_numeric" throughout.
Now the code runs and produces a plot.
filename = 'your_excel_file.xlsx';
bilinear_fit_capacity_curve_from_excel(filename);
function [V_design, D_design] = bilinear_fit_capacity_curve_from_excel(filename)
% Bilinear curve fitting of capacity curve from Excel file according to FEMA guidelines
% filename - Name of the Excel file
% Read data from Excel file
data = readtable('your_excel_file.xlsx');
D_capacity__str = data{:, 1}; % Displacement
V_capacity__str = data{:, 2}; % Base shear
% Convert base_shear from strings to numeric format
V_capacity__numeric = str2double(V_capacity__str);
% Check for any conversion errors (NaNs)
conversion_errors = isnan(V_capacity__numeric);
if any(conversion_errors)
% Handle conversion errors (e.g., replace NaNs with appropriate values)
% For example, you can set NaNs to zero:
V_capacity__numeric(conversion_errors) = 0;
end
% Convert base_shear from strings to numeric format
D_capacity_numeric = str2double(D_capacity__str);
% Check for any conversion errors (NaNs)
conversion_errors = isnan(D_capacity_numeric);
if any(conversion_errors)
% Handle conversion errors (e.g., replace NaNs with appropriate values)
% For example, you can set NaNs to zero:
D_capacity_numeric(conversion_errors) = 0;
end
% Find the yield point
[V_y, idx_y] = max(V_capacity__numeric);
% Find the ultimate point
[V_ult, idx_ult] = min(V_capacity__numeric);
% Define the first segment slope
slope1 = (V_y - 0) / D_capacity_numeric(idx_y);
% Define the second segment slope
slope2 = (V_ult - V_y) / (D_capacity_numeric(idx_ult) - D_capacity_numeric(idx_y));
% Calculate the bilinearized curve
V_design = zeros(size(V_capacity__numeric));
D_design = zeros(size(D_capacity_numeric));
% First segment
V_design(1:idx_y) = slope1 * D_capacity_numeric(1:idx_y);
D_design(1:idx_y) = D_capacity_numeric(1:idx_y);
% Second segment
V_design(idx_y+1:end) = V_y + slope2 * (D_capacity_numeric(idx_y+1:end) - D_capacity_numeric(idx_y));
D_design(idx_y+1:end) = D_capacity_numeric(idx_y+1:end);
% Plot original and bilinearized capacity curves
figure;
plot(D_capacity_numeric, V_capacity__numeric, 'b-', 'LineWidth', 2);
hold on;
plot(D_design, V_design, 'r--', 'LineWidth', 2);
xlabel('Displacement');
ylabel('Base Shear (V)');
title('Capacity Curve Bilinear Fitting');
legend('Original Capacity Curve', 'Bilinearized Curve');
grid on;
hold off;
end
  1 Comment
Cris LaPierre
Cris LaPierre on 29 Jan 2024
See the Access Data in Tables page. Use curly braces or dot notation and the variable name. I find the variable name often easier to remember than the column number.
data = readtable('your_excel_file.xlsx')
data = 51×2 table
displacement base_shear ____________ ___________ {'0.002'} {'92.0295'} {'0.02' } {'920.295'} {'0.04' } {'1840.59'} {'0.06' } {'2760.89'} {'0.08' } {'3676.04'} {'0.1' } {'4549.25'} {'0.12' } {'5255.34'} {'0.14' } {'5624.14'} {'0.16' } {'5922.58'} {'0.18' } {'6173.37'} {'0.2' } {'6348.77'} {'0.22' } {'6461.03'} {'0.24' } {'6612.06'} {'0.26' } {'6673.27'} {'0.28' } {'6663.94'} {'0.3' } {'6724.78'}
D_capacity__str = data.displacement; % Displacement
V_capacity__str = data.base_shear; % Base shear

Sign in to comment.

Categories

Find more on Fit Postprocessing in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!