Save data from for loop into array
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi,
I'm writing a piece of code to analyse some mechanical testing data. I am trying to save the data from the for loop into an array. However, I'm encountering an error each time. It reads an excel table, and then plots the force and extension through iterating through the spreadsheet. I am just can't figure out how to extract the maximum forces into an array. Here is the code.
clc
clear
close all
%% 5mm joints
figure()
A=readtable('Master-coupon-results-cleaned.xlsx','Sheet','5mm');
for i=0:3:(width(A)-1)
Force=A{:,2+i};
Stroke=A{:,3+i};
MaxForces=max(A{:,2+i})
Max(i)=MaxForces
plot(Stroke,Force)
hold on
grid on
xlabel('Displacement (mm)')
ylabel('Force (N)')
title('Force vs displacement graph for 5mm lap joint')
end
2 Commenti
Risposta accettata
Voss
il 12 Ott 2022
Max(i)=MaxForces gives an error when i == 0, because indexing starts at 1.
Furthermore, i goes 0, 3, 6, ..., and I imagine you want those values to go into elements 1, 2, 3, ... of Max, so some adjustment is necessary. See below:
clc
clear
close all
%% 5mm joints
figure()
A=readtable('Master-coupon-results-cleaned.xlsx','Sheet','5mm');
for i=0:3:(width(A)-1)
Force=A{:,2+i};
Stroke=A{:,3+i};
MaxForces=max(A{:,2+i});
% Max(i)=MaxForces
Max(i/3+1)=MaxForces; % i==0 -> index 1, i==3 -> index 2, etc.
plot(Stroke,Force)
hold on
grid on
xlabel('Displacement (mm)')
ylabel('Force (N)')
title('Force vs displacement graph for 5mm lap joint')
end
disp(Max);
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Animation in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
