Hi,
I would like to save data (that answer some conditions) from 2 different tables (T1, T2) to a new table (T3).
I tried to declare T3 and change the table's variable names but instead of a table, T3 is a structure.
T3.deltaY(r) = T2.y2(i) - T1.y1(j);
T3.x2(r) = T2.x2(i);
T3.x1(r) = T1.x1(j);
another question is how can I determine the size of the table in advanse instead of adding a new row at a time?
thanks!

답변 (2개)

Bhaskar R
Bhaskar R 2020년 1월 20일

0 개 추천

After your opeartion, you can apply
T3 = struct2table(T3); % converts from struct to table
[r, c] = size(T3); % to find the size table

댓글 수: 1

sani
sani 2020년 1월 20일
Thanks!
I'm not sure this is what I meant. I want to avoid using structure at the first place, is there's a way I can initiate T3 size before writing into it?

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

Stephen23
Stephen23 2020년 1월 20일

0 개 추천

For historic and compatibility reasons if the variable does not exist before the dot-indexing allocates to it, then MATLAB will initialize the variable as a structure:
>> clear
>> S.F = 1
S =
F: 1
>> class(S)
ans =
struct
If you want the variable to be a table then preallocate the table before the allocation:
>> T = table();
>> T.F = 1
T =
F
_
1
>> class(T)
ans =
table

댓글 수: 1

sani
sani 2020년 1월 20일
T3 = table();
T3.Properties.VariableNames{1} = 'deltaY';
T3.Properties.VariableNames{2} = 'x2';
T3.Properties.VariableNames{3} = 'x1';
for r = 1:height(T1(:,1))
for i = 1:height(T2(:,1))
T3.deltaY(r) = table2cell(T2.y2(i) - T1.y1(j));
T3.x2(r) = T2.x2(i);
T3.x1(r) = T1.x1(j);
end
end
I preallocate T3 as a table, but every time r edvanced a new row is addad in T3 which is very unefficient.

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

카테고리

도움말 센터File Exchange에서 Tables에 대해 자세히 알아보기

태그

질문:

2020년 1월 20일

댓글:

2020년 1월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by