Not showing lines and curves in the plot.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Respuestas (1)
Voss
el 29 de En. de 2024
Editada: Voss
el 29 de En. de 2024
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 comentario
Cris LaPierre
el 29 de En. de 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')
D_capacity__str = data.displacement; % Displacement
V_capacity__str = data.base_shear; % Base shear
Ver también
Categorías
Más información sobre Fit Postprocessing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
