hi.... my question is how to store string in matrix form and the matrix should me nxn matrix and it should take only square number for example 2x2 or 4x4 or 8x8 or 16x16 etc... please help me

3 views (last 30 days)
We are doing a project on data encryption and data decryption please help us with code.. my question is how to store string in matrix form and the matrix should me nxn matrix and it should take only square number for example 2x2 or 4x4 or 8x8 or 16x16 etc... please help me
  4 Comments
Walter Roberson
Walter Roberson on 5 Feb 2016
2 is not a square number in 2x2,so you are allowing non-square numbers. If the output array needs to be square then why is 3x3 or 6x6 not allowed?
radhika s gowda
radhika s gowda on 5 Feb 2016
Ya... Your correct but if we need to store the string to matrix for example take string as radhikasg it should be in 3x3 means r a d h i k a s g So how can i store this...

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 5 Feb 2016
L = length(YourString);
N = ceil(sqrt(L));
A = char('0' * ones(N,N));
A(1:L) = YourString;

More Answers (2)

KSSV
KSSV on 5 Feb 2016
You can define the strings into a cell. Check the example below:
m = 2 ;
iwant = cell(2) ;
iwant{1,1} = 'I' ;
iwant{1,2} = 'LOVE' ;
iwant{2,1} = 'MAT' ;
iwant{2,2} = 'LAB' ;
iwant =
'I' 'Love'
'MAT' 'LAB'
You can put your strings in a loop and fix the positions where ever you want. You can access the strings by iwant{i,j}, where i = 1:2, and j = 1:2. I hope this is the one you are looking for.

radhika s gowda
radhika s gowda on 31 Mar 2016
Edited: Geoff Hayes on 31 Mar 2016
m a t l
m= b i s e
a s y 0
0 0 0 0
for the above matrix the actual string length matlabiseasy string lengtg is 12 I want a function that removes the zeros from matrix using string length and to display the content of matrix in string please please help me....

Categories

Find more on Characters and Strings in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!