Matlab help! Prepare a function m-file containing a function that prints a line
ID: 3763103 • Letter: M
Question
Matlab help!
Explanation / Answer
function structure(s)
field_name =fieldnames(s);
val1 =getfield(s, cell2mat(field_name(1,1)));
val2 =getfield(s, cell2mat(field_name(2,1)));
fprintf('%s %f %f %f %f ',val1,val2(1),val2(2),val2(3),val2(4));
end
---------------------Test Program-------------------------------------
clc;
clear all;
s1 = struct('f1','Hello','f2',double(rand(4,1)*10));
s2 = struct('f1','Hiiii','f2',double(rand(4,1)*10));
structure(s1);
structure(s2);
-----------------------------Output-----------------------------------------------------
Hello 0.855158 2.624822 8.010146 0.292203
Hiiii 9.288541 7.303309 4.886090 5.785251
>>