how can i print 3 different vectors' while every vector contain different variable type?
1 回表示 (過去 30 日間)
古いコメントを表示
hello,
I have a code that make 3 vector that 2 of them should contain integers and the other conatain str.
I am trying to connected them to a matrix that every column is one vector but with no succes
happy to get some help were i am wrong
function mat= ws(noe) %ws=waterstatus
y=cell(noe,3);
% y1=1:noe;
% y2=1:noe;
% y3=cell(noe,3);
for i = 1:noe
%smaller loop
for j =1:3
if j==1
x1=input('experiment date : ','s');
y{i,1}=x1;
end
if j==2
x2=input('The amount of heavy metals absorbed : ','s');
y{i,2}=x2;
end
if j==3
x3=input('The name of the locality where the sample was taken : ','s');
y{i,3}=x3;
end
end
end
% y4=1:noe;
% y5=y3(y4);
% y6=char(y5');
% disp(y1') ,disp(y2'), disp(y6)
% % disp([y1,y2,char(y5')]);
% disp(y1')
% disp(y2')
% disp([y1', y2', y6])
% g=sprintf('%d %d %s', y1', y2', y6)
mat=cell2mat(y)
end
0 件のコメント
回答 (1 件)
Jan
2022 年 12 月 10 日
編集済み: Jan
2022 年 12 月 10 日
Vectors, matrices and other arrays (except for cell array) contain elements of the same class. This is the definition of an array: The class of the array is the class of its elements.
Only cell arrays are an exeption, which can contain elements of different classes and sizes.
In the title of the question, you ask for printing. In the body of the question and the code to try to create a matrix of mixed classes.
In the text you mention "make 3 vector that 2 of them should contain integers and the other conatain str". The code inserts 3 char vectors, so all have the same class in opposite to the description.
So what is the actual problem you want to solve? Printing or storing the data?
You code fails, when the CHAR vectors have not matching sizes.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Operators and Elementary Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!