Best Way to create bigger table?

9 ビュー (過去 30 日間)
Leon Stolp
Leon Stolp 2020 年 5 月 8 日
コメント済み: Ameer Hamza 2020 年 5 月 11 日
Hello everybody,
I need to create a Table for my calculations in Matlab. The Table is supposed to be about 2x300 Cells in size, I need to type the numbers in myself. So I'm wondering what the quickest way would be to do that. Meaning: Which way involves the least amount of characters and symbols.
The table should have a a row/colum with indexing numbers and another one with the value for that specific number. It should be possible to extract that specific number by calling the index number. So, i.e.
2 4
3 6
4 8
And when I call "3" in my calculation it will use "6" as the value for the calculation.
I'm having quite a hard time getting myself motivated, so I'm trying to make it as quick as possible... I know that I just could type it in with the "table" command, but I don't know which is the quickest way to make the indexing possible.
Any help will be greatly appreciated!

回答 (1 件)

Ameer Hamza
Ameer Hamza 2020 年 5 月 8 日
編集済み: Ameer Hamza 2020 年 5 月 8 日
You can create a function handle like this
A = [...
2 4
3 6
4 8];
A_fun = @(x) A(A(:,1)==x, 2);
Examples
>> A_fun(2)
ans =
4
>> A_fun(3)
ans =
6
>> A_fun(4)
ans =
8
  2 件のコメント
Leon Stolp
Leon Stolp 2020 年 5 月 11 日
編集済み: Leon Stolp 2020 年 5 月 11 日
Thank you!
Do you have an idea how to interpolate results within this example? i.e. between 2 and 3?
Ameer Hamza
Ameer Hamza 2020 年 5 月 11 日
Yes. See interp1(). Example
y = interp1([2 3 4], [4 6 7], 2.5)

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by