How to display a string in a matrix
Show older comments
so I'm supposed to write a function that takes an input of a string and an integer and then creates a square using the string to make it up and the integer as the dimensions. Here is an example:
square('.',6)
......
......
......
......
......
......
this is what I have as code:
function [ ] = square( s,num )
square = zeros(num, num);
for i = 1:num
for j=1:num
square(i,j) = s;
end
end
format
square
end
my output when I input ('.',6) is
46 46 46 46 46 46
46 46 46 46 46 46
46 46 46 46 46 46
46 46 46 46 46 46
46 46 46 46 46 46
46 46 46 46 46 46
what am I doing wrong??
Accepted Answer
More Answers (0)
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!