how to form a matrix with non-numeral entries and then set conditions for each case

1 回表示 (過去 30 日間)
I want to form a 1*n matrix which have enries of only two cases (like h and c) which are non-numeral as below:
A[1,n]={'h','c'}
A[1,n]=[h c h h h ......c]
and then set a condition if the case is "h" or "c", like
for i=1:n
If A[1,i]==h
Statement
end
However this way of forming code is not correct
I would really appreciate if I cn have your support.
NOH=3;
NOC=2;
Tetta=70*pi/180
for i=1:NOC+NOH
A(1,i)={'h','c'};
A(1,i)=input ('Please enter orientation of ith layer:');
if A(1,i)==h
t_h(i)=0.36
else if A(1,i)==c
t_c(i)=0.85
end
end
end

採用された回答

Awais Saeed
Awais Saeed 2021 年 9 月 2 日
I have made some corrections in your code
clc;clear all;close all
NOH=3;
NOC=2;
Tetta=70*pi/180
A = {}
for i=1:NOC+NOH
i
A(1,i) = input ('Please enter orientation of ith layer:');
if strcmp(A(1,i), 'h') % use strcmp to compare string
% Do not use == for string comparison
t_h(i) = 0.36
elseif strcmp(A(1,i), 'c')
t_c(i) = 0.85
end
end
  4 件のコメント
Awais Saeed
Awais Saeed 2021 年 9 月 2 日
Either enter your values as 'h' or 'c' (with quote marks) or replace input with
A{1,i} = input ('Please enter orientation of ith layer:', 's');
to be able to enter h and c (without any quote marks).
R@SH
R@SH 2021 年 9 月 2 日
I sincerely appreciate your both (awais and walter) support. now it works

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by