フィルターのクリア

How can I write "words" and time format in a matrix ?

2 ビュー (過去 30 日間)
zeezo
zeezo 2017 年 9 月 27 日
コメント済み: Walter Roberson 2017 年 9 月 27 日
I have this code
m=0.5
A = poissrnd(m, 24, 1);
for i=1:24;
if A(i,:)== 0;
DT(i,:)= 00:00:00; % I want it to be on time format, 00:00:00 How??
elseif 10>=A(i,:)>0;
DT(i,:)= 00:00:10; % I want it to be on time format , 00:00:10
else A(i,:)>10;
DT(i,:)=00:00:20; % I want it to be on time format, 00:00:20
end
end
As I write on the code how can I make the code to write time format?
Thank you you very much
  2 件のコメント
Jan
Jan 2017 年 9 月 27 日
編集済み: Jan 2017 年 9 月 27 日
It depends on what you want DT to be. A datetime vector?
What does this mean:
As I write on the code how can I make the code to type ' no delay'
and write time format?
zeezo
zeezo 2017 年 9 月 27 日
It was a mistake. I edit the question and I forget to delete it.

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

回答 (2 件)

Jan
Jan 2017 年 9 月 27 日
sec = zeros(size(A));
sec(0 < A & A <= 10) = 10;
sec(A > 10) = 20;
DT = datetime(0, 0, 0, 0, 0, sec, 'Format', 'HH:mm:ss');
Note:
elseif 10 >= A(i,:) > 0
This will not do, what you expect. Matlab evaluates this from left to right. In the first step 10 >= A(i, :) replies a logical vector, which contains TRUE or FALSE. Then TRUE > 0 or FALSE > 0 is calculated. You mean:
elseif 10 >= A(i,:) && A(i, :) > 0
  1 件のコメント
zeezo
zeezo 2017 年 9 月 27 日
Thank you I will try it. and I will get back :)

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


Walter Roberson
Walter Roberson 2017 年 9 月 27 日
It is not possible to put strings or datetime items into a numeric array.
You can construct cell arrays, or you can construct table objects.
  2 件のコメント
zeezo
zeezo 2017 年 9 月 27 日
How can I construct table objects?

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by