필터 지우기
필터 지우기

Text and Number in a Matrix/row

조회 수: 4 (최근 30일)
Dhirendu Somani
Dhirendu Somani 2021년 1월 26일
댓글: Dhirendu Somani 2021년 1월 30일
I want to create a row which include both numbers and text.
Sample Code
%%%% Input %%%%%%%
Text : {'x1=','y1=','z1='}
Nos : [1:1:3];
% Sample Code
for i=1:length(Nos)
Row(1,i) = Text(i);
Row(1,i+1) = Nos(i);
end
% Need Output as below
Row = [ x1=1 y1=2 z1=3 ]; % (numbers and text in alternate columns )
% Attached image for needed output
  댓글 수: 5
Dhirendu Somani
Dhirendu Somani 2021년 1월 28일
@Mathieu NOE Yes my goal is to store in 6 columns like a excel file
Mathieu NOE
Mathieu NOE 2021년 1월 28일
hello
would it be just one line as the format you showed or dou you intend to have column oriented vectors for x1, y1, z1 ?
if yes maybe you should put those three labels as header line in the first row and then store the vectors below (my 2 cents)

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2021년 1월 28일
Text = {'x1=','y1=','z1='}
Text = 1x3 cell array
{'x1='} {'y1='} {'z1='}
Nos = [1:1:3]
Nos = 1×3
1 2 3
Noscell = num2cell(Nos)
Noscell = 1x3 cell array
{[1]} {[2]} {[3]}
Output = reshape([Text(:).'; Noscell(:).'], 1, [])
Output = 1x6 cell array
{'x1='} {[1]} {'y1='} {[2]} {'z1='} {[3]}

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

제품


릴리스

R2016b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by