How to reshape an matrix made from an input turned into a double value?

1 回表示 (過去 30 日間)
Luke fleenor
Luke fleenor 2016 年 10 月 16 日
回答済み: Massimo Zanetti 2016 年 10 月 17 日
str= input('Please enter message here: ','s' );
n= double(str);
a= reshape(n,2,2);
encrypt = [110,2221;213,4769];
h=a*encrypt;
disp(h)
This code returns the error:
Error using reshape To RESHAPE the number of elements must not change.
Error in Luke_FLeenor_Matlab_Project (line 11) a= reshape(n,2,2);
What can I do to reshape that array?
  1 件のコメント
Walter Roberson
Walter Roberson 2016 年 10 月 16 日
Your reshape will fail unless your string has exactly 4 characters.
If you have an even number of characters, reshape(n, [], 2)

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

回答 (1 件)

Massimo Zanetti
Massimo Zanetti 2016 年 10 月 17 日
Your code only works for 4-characters long strings because you are reshaping them to 2x2 matrix.

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by