How to assign a vector with predefined data?

3 ビュー (過去 30 日間)
israt fatema
israt fatema 2021 年 8 月 25 日
コメント済み: israt fatema 2021 年 8 月 30 日
I need to a assign a n x n vector with data and use that vector to call a function. All example i found is for creating random or zero vector.
x size n x n (5 x 5) and n must equal length(y), and y size n x 1
A = [10695.88;10446.39;10082.36;9760.39;9390.26];
B = [10705.50;10439.13;10171.95;9794.65;9455.76];
x = vector of A with size 5 x 5 ?
y = vector of B with 5 x 1 ?
Thank you.

採用された回答

Shanmukha Voggu
Shanmukha Voggu 2021 年 8 月 30 日
Hi fatema,
I understand that you want to create a vector with predefined data instead of using zeros, ones, rand functions.
let's create a vector A(5 x 1)
A=[1;2;3;4;5]
A = 5×1
1 2 3 4 5
let's create a vector B(5 x 5) from the predefined data(A)
B=A(:,[1,1,1,1,1])
B = 5×5
1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5
The same result as above can be achieved by doing the following
RowCount = size(A, 1)
RowCount = 5
ColumnIndexes = ones(1, RowCount)
ColumnIndexes = 1×5
1 1 1 1 1
B=A(:, ColumnIndexes)
B = 5×5
1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5
The best way to use the predefined data is to index it to get the desired results. refer to this document for more info.
  1 件のコメント
israt fatema
israt fatema 2021 年 8 月 30 日
Thank you very much.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Object Identification についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by