function ret = p_analyze(varargin) % % varargin = fname1, rows1, fname2, rows2, ... % %cellplot(varargin) temp_file = 'temp.mat'; max_rows = 0; try load(temp_file); [files, stored_index] = size(ret); for i = 1:files rows = size(ret(i, 1).p); rows = rows(1); max_rows = max(max_rows, rows); end catch files = size(varargin); files = files(2) / 2; for f_index = 1:files [fname, rows] = deal(varargin{(f_index * 2 - 1):(f_index * 2)}); max_rows = max(max_rows, rows); fid = fopen(fname); sprintf('target file => %s\n', fname) a = fscanf(fid, '%e ',[((rows * rows) + 1) inf]); fclose(fid); [row_column, items] = size(a); items = items - 1; sprintf('total data => %d\n', items) stored_index = 0; for loop = 1:items if 0 ~= mod(loop, 100) continue end stored_index = stored_index + 1; v = zeros(rows, rows); num = 1; ret(f_index, stored_index).ts = a(num, loop); %#ok for i = 1:rows for j = 1:rows num = num + 1; v(i,j) = a(num, loop); end end ret(f_index, stored_index).p = v; %#ok end clear a; end save(temp_file, 'ret'); end % 対角要素のグラフ if 0 for target_index = 1:max_rows figure; set(gca,'fontsize',16,'fontname','Helvetica'); hold on; %c = colormap; for f_index = 1:files t = []; y = []; try for i = 1:stored_index t(i) = ret(f_index, i).ts; y(i) = ret(f_index, i).p(target_index, target_index); end catch end %semilogy(t, y, 'color', c(f_index*16,:)); c = [0 0 0]; switch(f_index) case 1 c = [1 0 0]; case 2 c = [0 1 0]; case 3 c = [0 0 1]; end semilogy(t, y, 'color', c); end hold off; end end % 姿勢(8:10)について主成分分析 for target_index = 8:10 figure; set(gca,'fontsize',16,'fontname','Helvetica'); hold on; for f_index = 1:files t = []; y = []; t_s = []; v_s = []; d_s = []; t_y_index = 1; for i = 1:stored_index try % 固有値、固有ベクトルを求める [v, d] = eig(ret(f_index, i).p); t_s = cat(1, t_s, ret(f_index, i).ts); v_s = cat(2, v_s, v); d_s = cat(2, d_s, d); % target_indexが最大となる固有ベクトルの位置 [rows, columns] = size(v); j = 1; max_i2 = 0; second_i2 = 0; while j <= columns max_elm = 0; max_i2 = 0; second_elm = 0; second_i2 = 0; for i2 = 1:rows if max_elm < abs(v(i2, j)) second_elm = max_elm; second_i2 = max_i2; max_elm = abs(v(i2, j)); max_i2 = i2; elseif second_elm < abs(v(i2, j)) second_elm = abs(v(i2, j)); second_i2 = i2; end end if target_index == max_i2 break end j = j + 1; end % その固有値を記録 y(t_y_index) = d(j, j); t(t_y_index) = ret(f_index, i).ts; t_y_index = t_y_index + 1; catch end end dlmwrite(sprintf('t_%d.csv', f_index), t_s, 'delimiter', ',', 'precision', 16); dlmwrite(sprintf('v_%d.csv', f_index), v_s, 'delimiter', ',', 'precision', 16); dlmwrite(sprintf('d_%d.csv', f_index), d_s, 'delimiter', ',', 'precision', 16); c = [0 0 0]; switch(f_index) case 1 c = [1 0 0]; case 2 c = [0 1 0]; case 3 c = [0 0 1]; end plot(t, y, 'color', c); end hold off; end