how to assign the value to the matrix

3 ビュー (過去 30 日間)
rupak katwal
rupak katwal 2019 年 9 月 28 日
編集済み: rupak katwal 2019 年 10 月 1 日
I have the string suppose 'aB@2', Now i first i want to create the matrix with the character of these string.
λ a B @ 2
λ 0 a B @ 2
a 0 aa aB a@ a2
B 0 Ba BB B@ B2
@ 0 @a @B @@ @2
2 0 2a 2B 2@ 4
Now,i have the text file containing these strings
122 Ba@2
123 a@2B
144 2@Ba
From the first string 122 Ba@2, the character after the first space is:
Ba@2
i want to update the above matrix as
a 122 @ 2 2
0 aa aB 122 a2
0 122 BB B@ B2
0 @a @B @@ 122
0 2a 2B 2@ 4
From this way i want update the above matrix along with the list of string in text file.
  1 件のコメント
Stephen23
Stephen23 2019 年 10 月 1 日
@rupak katwal: please show the expected output matrix for the example data you provide in your question.

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

回答 (1 件)

Dinesh Yadav
Dinesh Yadav 2019 年 10 月 1 日
I am attaching a code which helps you generate a cell array of how you want your matrix to look like. It’s a pseudo code, you can make changes to it to generalize it as you want.
After you have generated the cell matrix compare each element of cell matrix like if element(i,j)==”B”then replace it with 122 and so on for the other elements too.
z = ['a','B','@','2'];
z1 = ['a','B','@','2']; %copy of above array for simplicity of use
arr = cell(5,5);
for i = 1:5
for j=1:5
if(j==1)
arr{i,j}=0;
elseif (j~=1 && i==1)
arr{i,j}= z(j-1);
else
arr{i,j}=strcat(z(i-1),z1(j-1));
end
end
end
  1 件のコメント
Stephen23
Stephen23 2019 年 10 月 1 日
編集済み: Stephen23 2019 年 10 月 1 日
Note that [] is a concatenation operator, so
z = ['a','B','@','2'];
is just a complex way of defining this character vector:
z = 'aB@2';

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

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by