MATLAB Answers

# Changing Values of a Large Array

2 views (last 30 days)
Matthew Lancaster on 25 Oct 2021
Commented: Matthew Lancaster on 25 Oct 2021
So I am trying to change data in a 2716 by 1 array. I imported the data for this array from a text file. I need to change the last 665 lines of data in a new array and still have the original data as the first part of the array.
%%
%For true stress/strain we need to create the reduction of area as necking
%occurs
% point at which necking occurs: stress = 312.8 Mpa
true_Load = M.Load*1000; %kN
load_location = 312.8*area/1000; %location in text file
load_location;
%Necking begins: line 2043
%Fracture: line 2724
%2724-2043 = 681 lines of data need to be recreated for stress
%now that we have the location of the UTS we can take that and begin the
%reduction from original area to fracture area
reduc_Area = linspace(area, frac_Area, 665);
%redcu_Area should have comperable data for the
%necking that occurs till fracture. We now need to make
%true stress by inputting the extrapolated values into a new
%stress file
true_Stress = stress;
true_tress(2043:2716,:) = true_Load(2043:2716,:)/reduc_Area(2043:2716,:);
When I run this code I get:
Index in position 1 exceeds array bounds (must not exceed 1).
Error in AL6061_0hr (line 107)
true_tress(1:2716,:) = true_Load(2043:2716,:)/reduc_Area(2043:2716,:);
I have tried multiple things of what I thought would work but can not figure it out.
##### 1 CommentShowHide None
Matthew Lancaster on 25 Oct 2021
I figured it out, the fix was:
%%
%For true stress/strain we need to create the reduction of area as necking
%occurs
% point at which necking occurs: stress = 312.8 Mpa
true_Load = M.Load*1000; %kN
load_location = 312.8*area/1000; %location in text file
load_location;
%Necking begins: line 2043
%Fracture: line 2724
%2724-2043 = 681 lines of data need to be recreated for stress
%now that we have the location of the UTS we can take that and begin the
%reduction from original area to fracture area
reduc_Area = linspace(area, frac_Area, 674);
reduc_Area';
%redcu_Area should have comperable data for the
%necking that occurs till fracture. We now need to make
%true stress by inputting the extrapolated values into a new
%stress file
true_Stress = stress;
% true_Stress(2043:2716,:) = true_Load(2043:2716,:);
% true_Stress(2043:2716,:) = true_Stress(2043:2716,:)/reduc_Area(1:);
for i = 1:673
reduced_Area = reduc_Area(:,i);
true_Stress(2043+i,:) = true_Load(2043+i,:)/reduced_Area;
end%We now have true stress
By incorporating the for loop I was able to go in and change the value. linspace was creating a 674 by 1 array and when I tried to divide the true_Stress by reduc_Area it wasn't allowing it.
The for loop allowed me to create a single variable to divide by.

Sign in to comment.

### Accepted Answer

Image Analyst on 25 Oct 2021
Edited: Image Analyst on 25 Oct 2021
Do not use two dimensions for a 1-D array. And you can do it vectorized (no for loop) if you use ./ like this:
true_Stress = stress; % Initialize.
true_Stress(2043:2716) = true_Load(2043:2716) ./ reduc_Area; % Element by element division.
##### 1 CommentShowHide None
Matthew Lancaster on 25 Oct 2021
Thank you

Sign in to comment.

R2020a

### Community Treasure Hunt

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

Start Hunting!

Translated by