Replacing Matrix Cells with Date Values
    5 ビュー (過去 30 日間)
  
       古いコメントを表示
    
Hi,
I am trying to replace the 1 values in a large matrix of cells with the date value stored in a single row. 
Matlab doesn't seem to like dimension mismatch or the form of the date cells, but I need to keep them in date format for future analysis. 
Does anyone have any advice? or Help pages they could direct me to? 
   [1]    [0]    [0]    [0]    [0]    [0]    [0]
    [1]    [0]    [0]    [0]    [0]    [0]    [0]
    [0]    [0]    [0]    [0]    [1]    [0]    [0]
    [0]    [0]    [0]    [0]    [0]    [0]    [0]
    [0]    [0]    [0]    [1]    [0]    [0]    [0]
    [0]    [0]    [0]    [0]    [0]    [0]    [0]
    [0]    [0]    [0]    [1]    [0]    [0]    [0]
    [0]    [1]    [0]    [0]    [0]    [0]    [0]
    [0]    [0]    [0]    [0]    [1]    [0]    [0]
    [0]    [0]    [0]    [0]    [0]    [0]    [0]
    [0]    [0]    [0]    [0]    [0]    [0]    [0]
    [0]    [0]    [0]    [0]    [1]    [0]    [0]
    [0]    [0]    [0]    [1]    [0]    [0]    [0]
    [0]    [0]    [0]    [1]    [0]    [0]    [0]
    [0]    [0]    [0]    [0]    [0]    [0]    [0]
    [0]    [0]    [0]    [0]    [0]    [0]    [1]
    [1]    [0]    [0]    [0]    [0]    [0]    [0]
    [0]    [0]    [1]    [0]    [0]    [0]    [0]
    [0]    [0]    [0]    [0]    [0]    [0]    [0]
    [0]    [0]    [0]    [0]    [0]    [0]    [0]
    [1]    [0]    [0]    [0]    [0]    [0]    [0]
    [0]    [0]    [0]    [0]    [0]    [0]    [0]
    [0]    [0]    [0]    [0]    [0]    [0]    [1]
    [0]    [0]    [0]    [0]    [0]    [0]    [0]
    [0]    [0]    [1]    [0]    [0]    [0]    [0]
    [0]    [0]    [1]    [0]    [0]    [0]    [0]
    [0]    [0]    [0]    [0]    [0]    [1]    [0]
    [0]    [0]    [0]    [0]    [1]    [0]    [0]
Columns 1 through 5
    '01/04/2004'    '02/04/2004'    '03/04/2004'    '04/04/2004'    '05/04/2004'
Columns 6 through 7
    '06/04/2004'    '07/04/2004'
I have an equal number of columns in each set, I would just like every one in the matrix to represent the date for corresponding column number.
 Thank you for any help/advice/direction!
0 件のコメント
採用された回答
  Azzi Abdelmalek
      
      
 2015 年 6 月 2 日
        d={'01/04/2004'    '02/04/2004'    '03/04/2004'    '04/04/2004'    '05/04/2004'    '06/04/2004'    '07/04/2004'}
v=num2cell(randi([0 1],4,7))
idx=cell2mat(v)==1
for k=1:7
  v(idx(:,k),k)=d(k)
end
その他の回答 (1 件)
  Andrei Bobrov
      
      
 2015 年 6 月 2 日
        d = {'01/04/2004'    '02/04/2004'    '03/04/2004'...
     '04/04/2004'    '05/04/2004'    '06/04/2004'    '07/04/2004'};
out = {  [1]    [0]    [0]    [0]    [0]    [0]    [0]
    [1]    [0]    [0]    [0]    [0]    [0]    [0]
    [0]    [0]    [0]    [0]    [1]    [0]    [0]
    [0]    [0]    [0]    [0]    [0]    [0]    [0]
    [0]    [0]    [0]    [1]    [0]    [0]    [0]
    [0]    [0]    [0]    [0]    [0]    [0]    [0]
    [0]    [0]    [0]    [1]    [0]    [0]    [0]
    [0]    [1]    [0]    [0]    [0]    [0]    [0]
    [0]    [0]    [0]    [0]    [1]    [0]    [0]
    [0]    [0]    [0]    [0]    [0]    [0]    [0]
    [0]    [0]    [0]    [0]    [0]    [0]    [0]
    [0]    [0]    [0]    [0]    [1]    [0]    [0]
    [0]    [0]    [0]    [1]    [0]    [0]    [0]
    [0]    [0]    [0]    [1]    [0]    [0]    [0]
    [0]    [0]    [0]    [0]    [0]    [0]    [0]
    [0]    [0]    [0]    [0]    [0]    [0]    [1]
    [1]    [0]    [0]    [0]    [0]    [0]    [0]
    [0]    [0]    [1]    [0]    [0]    [0]    [0]
    [0]    [0]    [0]    [0]    [0]    [0]    [0]
    [0]    [0]    [0]    [0]    [0]    [0]    [0]
    [1]    [0]    [0]    [0]    [0]    [0]    [0]
    [0]    [0]    [0]    [0]    [0]    [0]    [0]
    [0]    [0]    [0]    [0]    [0]    [0]    [1]
    [0]    [0]    [0]    [0]    [0]    [0]    [0]
    [0]    [0]    [1]    [0]    [0]    [0]    [0]
    [0]    [0]    [1]    [0]    [0]    [0]    [0]
    [0]    [0]    [0]    [0]    [0]    [1]    [0]
    [0]    [0]    [0]    [0]    [1]    [0]    [0]};
a2 = cell2mat(out);
[~,jj] = find(a2);
out(a2>0) = d(jj);
参考
カテゴリ
				Help Center および File Exchange で Dates and Time についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


