cell array or matrix for complex subtraction calculation

Hi, I used excel to import a table (table B) which has 24 columns and 200000 rows. I have another table (table A) which has only one column and 24 rows. I want to subtract table A from table B in such a manner that the first 24 rows of each column (table B) are subtracted from table A, then the next consecutive rows of table B are subtracted from table A, then the next consecutive rows and so on until all 200000 rows are completed. The example below illustrates what I want to do:
row 0-24 from table B minus 24 rows from Table A row 25-49 from table B minus 24 rows from Table A and so on.
the subtract should be done in such a manner that I get an absolute value.
1) How shall I import the files? Matlab offers many options: matrices, vectors, cell arrays, table format 2) Shall I use a command or a script to run this calculation and how do I write the command or script? 3) I have many table Bs' which are named MM30 to MM120. So 90 different tables Bs' and I want a loop that performs this complex calculation between table A and all table Bs.
I really appreciate your help.

2 件のコメント

Andrei Bobrov
Andrei Bobrov 2014 年 9 月 29 日
What is M30 - .mat, .xls or .txt - file or variable of mat - file.
AA
AA 2014 年 9 月 29 日
M30 is an xlsb excel file. I have imported it into matlab. I do not know which format I should import it as. Matrix, vector, table or cell array?

サインインしてコメントする。

 採用された回答

Andrei Bobrov
Andrei Bobrov 2014 年 9 月 29 日
編集済み: Andrei Bobrov 2014 年 9 月 29 日

0 投票

s = size(B);
s2 = numel(A);
k = ceil(s(1)/s2);
out = [B;nan(mod(-s(1),s2),s(2))] - kron(ones(k,s(2)),A);
% or out = [B;nan(mod(-s(1),s2),s(2))] - repmat(A,k,s(2));
one way
cd path/to/your/dir % here path to dir where your xlsx - files
n = dir('MM*.xlsb');
n1 = {n.name};
nn = numel(n);
out = cell(nn,1);
s2 = numel(A);
for ii = 1:nn
B = xlsread(n1{ii});
s = size(B);
k = ceil(s(1)/s2);
out{ii} = [B;nan(mod(-s(1),s2),s(2))] - repmat(A,k,s(2));
end

5 件のコメント

AA
AA 2014 年 9 月 29 日
do i have to import the data as vector, matrix or cell array before performing this operation? please help me on this.
AA
AA 2014 年 9 月 29 日
s1 is undefined. B and A are also undefined. are A and B representing the tables?
Andrei Bobrov
Andrei Bobrov 2014 年 9 月 29 日
I corrected
AA
AA 2014 年 10 月 7 日
sorry for asking this question but do i type this in the command window or script/editor?
AA
AA 2014 年 10 月 7 日
and also in which folder do the files get saved? i should get 90 different files as there are 90 different tables. thanks a lot

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeTables についてさらに検索

質問済み:

AA
2014 年 9 月 29 日

コメント済み:

AA
2014 年 10 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by