Multiplying elements from various tables to create a third table

조회 수: 7 (최근 30일)
Hi there,
I'm a beginner to Matlab, and I have a very shaky foundation. However, I need the help of Matlab to do some analysis. I would highly appreciate your help!
I have two types of data sets I'm drawing from
(for n =1:82 tables) Table A_n(70080 x 4)
Table B(82 x 1)
Basically, I need to individually multiple the 'nth' element in Table B by the second column of Table A_n.
This should result in Table C (70080 x 82).
I know I can produce the variables for each column vector of Table C by inputting this:
Col_1 = A_1(:,2)*B(1,1);
Col_2 = A_2(:,2)*B(2,1);
...
Col_n = A_n(:,2)*B(n,1);
but it is manually taxing. Furthermore, I have no idea how to input these into an actual table. This would require some sort of concantenation?
Initially I wanted to dynamically create these variables but I have read elsewhere that doing so is actually quite troublesome.
Is there any way for me to input these variables directly into a table?
And to do this all through a for loop...
Thanks!
  댓글 수: 1
Christina Hong
Christina Hong 2020년 7월 28일
In the follow script, im getting close to my desired result
HOWEVER in the bold/italic/underlined section im trying to obtain the column vector of one table and the element of the other, but instead what I get returned is a string. How will I be able to obtain actual values?!
>> myFilenames = cell(8,1);
for i = 1:8
str = strcat('1000YearReturn_300deg_Story',' ', num2str(i),'.txt');
myFilenames{i} = str;
load(myFilenames{i});
end
>> myFilenames = cell(8,1);
momentY = cell(70080,1);
for i = 1:8
str = strcat('1000YearReturn_300deg_Story',' ', num2str(i),'.txt');
myFilenames{i} = str;
load(myFilenames{i});
story_i = strcat('X1000YearReturn_300deg_Story', ' ', num2str(i), '(:,2)');
refHeight = strcat('Referenceheights(', ' ', num2str(i), ',1)');
momentY{i} = story_i*refHeight;
mY = momentY{i};
T = [T mY];
end

댓글을 달려면 로그인하십시오.

채택된 답변

Christina Hong
Christina Hong 2020년 7월 30일
I was able to find the answer to my problem, successfully creating 3 70080x82 tables and using a loop to load in all 82 files
>> load Referenceheights.txt
myFilenames = cell(82,1);
My = [];
Mx = [];
Mz = [];
for i = 1:82
str = strcat('1000YearReturn_300deg_Story',' ', num2str(i),'.txt');
myFilenames{i} = str;
load(myFilenames{i});
S = load(myFilenames{i});
My(:,i) = S(:,2)*Referenceheights(i,1);
Mx(:,i) = S(:,3)*-Referenceheights(i,1);
Mz(:,i) = S(:,4);
end

추가 답변 (1개)

Mario Malic
Mario Malic 2020년 7월 28일
Check if it gives correct output.
C = (A(:,2)'.*B)';
  댓글 수: 4
Christina Hong
Christina Hong 2020년 7월 29일
Hi Mario,
I will compile all 82 resultant column vectors from Table A(:,2) x Table B(n,1) to form ONE table C with 82 columns.
Mario Malic
Mario Malic 2020년 7월 29일
편집: Mario Malic 2020년 7월 29일
The line that I wrote gives you the Variable C with (70080 x 82).

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by