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)
Show older comments
radhika s gowda
on 4 Feb 2016
Commented: Walter Roberson
on 31 Mar 2016
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
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?
Accepted Answer
Walter Roberson
on 5 Feb 2016
L = length(YourString);
N = ceil(sqrt(L));
A = char('0' * ones(N,N));
A(1:L) = YourString;
0 Comments
More Answers (2)
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.
0 Comments
See Also
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!