I want to add column 1st from data1 and coloumn 1st from data2, likewise addition of all coloumn.

1 次查看(过去 30 天)
DATA1
4 8 6
3 5 7
1 9 2
DATA2
7 8 4
5 2 4
1 7 9

采纳的回答

Stephen23
Stephen23 2016-3-1
编辑:Stephen23 2016-3-1
MATLAB makes these things really easy:
>> A = [
4 8 6
3 5 7
1 9 2];
>> B = [
7 8 4
5 2 4
1 7 9];
>> A + B
ans =
11 16 10
8 7 11
2 16 11
Note that it would probably be a bad idea to create three separate variables: programming is easiest when you keep your data together as much as possible (e.g. in one array, like I show), because then you can loop and apply to functions to an entire array.

更多回答(1 个)

Explorer
Explorer 2016-3-1
编辑:Explorer 2016-3-1
DATA1= [4 8 6; 3 5 7; 1 9 2]
DATA2= [7 8 4; 5 2 4; 1 7 9]
C1_sum=DATA1(:,1)+DATA2(:,1) % Sum of 1st Columns of DATA1 and DATA2
C2_sum=DATA1(:,2)+DATA2(:,2) % Sum of 2nd Columns of DATA1 and DATA2
C3_sum=DATA1(:,3)+DATA2(:,3) % Sum of 3rd Columns of DATA1 and DATA2
  2 个评论
Guillaume
Guillaume 2016-3-1
DO not number variables. As a rule, if you start numbering variables you're doing it wrong. You can't easily iterate over the variable (to apply the same function to each for example). And this obviously does not scale. What if you have 100 columns? Are you going to copy/paste the same line 100 times and edit each to change the index?
Use cell arrays or higher dimension matrices to store related variables. What is the point in creating three different variables to store 3 columns when they could all be stored in one matrix?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by