How to display a string in a matrix
Ältere Kommentare anzeigen
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??
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Characters and Strings finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!