Clear Filters
Clear Filters

How can I resolve Error Using max function

2 views (last 30 days)
clc
clear all;
close all;
for kk =1:44
for k=1:50
% here drift values are in the form of drift ratio
eval(['load IDAOutput/EQ_',num2str(kk),'/Scale_',num2str(k),'/StoryDrifts/','Roof.txt']);
Roof_Drift_max(kk,k,:)= max(abs(Roof(:,2)));
eval(['load IDAOutput/EQ_',num2str(kk),'/Scale_',num2str(k),'/StoryDrifts/','Story1.txt']);
Story1_Drift_max(kk,k,:)= max(abs(Story1(:,2)));
eval(['load IDAOutput/EQ_',num2str(kk),'/Scale_',num2str(k),'/StoryDrifts/','Story2.txt']);
Story2_Drift_max(kk,k,:)= max(abs(Story2(:,2)));
eval(['load IDAOutput/EQ_',num2str(kk),'/Scale_',num2str(k),'/StoryDrifts/','Story3.txt']);
Story3_Drift_max(kk,k,:)= max(abs(Story3(:,2)));
eval(['load IDAOutput/EQ_',num2str(kk),'/Scale_',num2str(k),'/StoryDrifts/','Story4.txt']);
Story4_Drift_max(kk,k,:)= max(abs(Story4(:,2)));
eval(['load IDAOutput/EQ_',num2str(kk),'/Scale_',num2str(k),'/StoryDrifts/','Story5.txt']);
Story5_Drift_max(kk,k,:)= max(abs(Story5(:,2)));
eval(['load IDAOutput/EQ_',num2str(kk),'/Scale_',num2str(k),'/StoryDrifts/','Story6.txt']);
Story6_Drift_max(kk,k,:)= max(abs(Story6(:,2)));
eval(['load IDAOutput/EQ_',num2str(kk),'/Scale_',num2str(k),'/StoryDrifts/','Story7.txt']);
Story7_Drift_max(kk,k,:)= max(abs(Story7(:,2)));
eval(['load IDAOutput/EQ_',num2str(kk),'/Scale_',num2str(k),'/StoryDrifts/','Story8.txt']);
Story8_Drift_max(kk,k,:)= max(abs(Story8(:,2)));
eval(['load IDAOutput/EQ_',num2str(kk),'/Scale_',num2str(k),'/StoryDrifts/','Story9.txt']);
Story9_Drift_max(kk,k,:)= max(abs(Story9(:,2)));
% Maximum Interstorey Drift Ratio
MIDR(kk,k,:) =max(Roof_Drift_max(kk,k,:),Story1_Drift_max(kk,k,:),Story2_Drift_max(kk,k,:),Story3_Drift_max(kk,k,:),Story4_Drift_max(kk,k,:),...
Story5_Drift_max(kk,k,:),Story6_Drift_max(kk,k,:),Story7_Drift_max(kk,k,:),Story8_Drift_max(kk,k,:),Story9_Drift_max(kk,k,:));
end
end

Accepted Answer

Star Strider
Star Strider on 8 Jan 2021
I am not certain what you want.
One option is to enclose all the arguments within square brackets [], effectively concatenating them:
MIDR(kk,k,:) =max([Roof_Drift_max(kk,k,:),Story1_Drift_max(kk,k,:),Story2_Drift_max(kk,k,:),Story3_Drift_max(kk,k,:),Story4_Drift_max(kk,k,:),...
Story5_Drift_max(kk,k,:),Story6_Drift_max(kk,k,:),Story7_Drift_max(kk,k,:),Story8_Drift_max(kk,k,:),Story9_Drift_max(kk,k,:)]);
This will produce an ‘MIDR’ matrix with the same dimensions as the argument matrices.
Experiment with other approaches to get different results.
  16 Comments
Sumit Saha
Sumit Saha on 9 Jan 2021
I've attached a zip file for your reference
Star Strider
Star Strider on 9 Jan 2021
Try this to extract the variables:
uz = unzip('IDAOutput.zip');
k2 = 0;
for k1 = 1:numel(uz)
if ~isdir(uz(k1))
[~,txtname] = fileparts(uz{k1});
k2 = k2+1;
LD{k2,1} = txtname;
LD{k2,2} = load(uz{k1});
end
end
I have to unzip it, so I included tahat as part of my code. Change my code to work with the .zip file or it was created from. My code extracts the contents of the .zip file to a series of cell arrays, with the first element of the cell array being the name of the file it came from, and the second cell array the contents of that file as a double matrix.
So to get the information for the first 5 elements of ‘LD(1)’:
BldgPart_1 = [LD{1,1}]
BldgPrtData_1 = [LD{1,2}(1:5,:)]
produces:
BldgPart_1 =
'Roof'
BldgPrtData_1 =
0.002 6.9378e-08
0.004 6.9378e-08
0.006 6.9378e-08
0.008 6.9378e-08
0.01 6.9378e-08
and for ‘LD(40)’:
BldgPart_40 = [LD{40,1}]
BldgPrtData_40 = [LD{40,2}(1:5,:)]
produces:
BldgPart_40 =
'Story9'
BldgPrtData_40 =
0.002 5.5276e-07
0.004 5.5276e-07
0.006 5.5276e-07
0.008 5.5276e-07
0.01 5.5276e-07
I leave the rest to you.

Sign in to comment.

More Answers (1)

Feng Shui Déco
Feng Shui Déco on 9 Jan 2021
Yeah, you have to close your arguments with square bracket.

Categories

Find more on Structures in Help Center and File Exchange

Products


Release

R2017a

Community Treasure Hunt

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

Start Hunting!