How to add data to table?

7 ビュー (過去 30 日間)
Andrew Ng Chee Wei
Andrew Ng Chee Wei 2022 年 7 月 14 日
コメント済み: Andrew Ng Chee Wei 2022 年 7 月 14 日
Helo everyone,
I'm currently trying to accept a number of different velocities, maximum height, horizontal distance and time taken into a table. However, the array constantly is getting updated as the program should allow me to add newer data like velocities and et cetera. And the table is only showing one column of data at a time and does not add to the next. May I know how to fix this?
I tried this method but it does not work. May anyone enlighten me?
%Table Values
for i = 1:app.AddSpinner.Value
v0table = zeros;
hdtable = zeros;
tttable = zeros;
hmtable = zeros;
v0table(:,i) = v0;
hdtable(:,i) = hd;
tttable(:,i) = time_flight;
hmtable(:,i) = hmax;
end
app.UITable.Data = [v0table,hdtable,tttable,hmtable];

回答 (1 件)

Amritesh
Amritesh 2022 年 7 月 14 日
編集済み: Amritesh 2022 年 7 月 14 日
You are initializing arrays in each iteration of for loop. Try following piece of code
v0table = zeros;
hdtable = zeros;
tttable = zeros;
hmtable = zeros;
for i = 1:app.AddSpinner.Value
v0table(i) = v0;
hdtable(i) = hd;
tttable(i) = time_flight;
hmtable(i) = hmax;
end
app.UITable.Data = [v0table,hdtable,tttable,hmtable];
If v0table(i) = v0; is not working try
v0table(end+1) = v0;
Hope this solves your problem.
  1 件のコメント
Andrew Ng Chee Wei
Andrew Ng Chee Wei 2022 年 7 月 14 日
Hello, I changed it and it works, but another problem sufficed. Is that when i want to add another row of data, for example:
velocity Time taken
5 60
This was when it first started, now i want to add another row of new data ; velocity 5 and timetaken =50
velocity time taken
5 50
5 50
How do i solve this?

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

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by