I have a bunch of 6x7 matrixes in matlab and I want to know how I can use sprint
ID: 3864024 • Letter: I
Question
I have a bunch of 6x7 matrixes in matlab and I want to know how I can use sprintf to print the values in of the colums in each row 1 by 1 so for example
1,2,3,4,5,6,7
8,9,10,11,12,13,14
it would print out 1
2
3
4
5
6
7
8
9
10.. and so on I want to print it vertically in the text document as well
Explanation / Answer
main.m
clc;
clear all;
close all;
%6x7 matrixes in matlab
a=[1 2 3 4 5 6 7;8 9 10 11 12 13 14;15 16 17 18 19 20 21;22 23 24 25 26 27 28;29 30 31 32 33 34 35;36 37 38 39 40 41 42;]
for i =1:size(a,1)
for j=1:size(a,2)
b=sprintf('%d',a(i,j));
disp(b)
end
end
Output:-
a =
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31 32 33 34 35
36 37 38 39 40 41 42
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.