From 854864db2ae603d7108ef1357182aef93f78845d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20L=C3=B6vfors?= <william.lovfors@gmail.com> Date: Wed, 24 Apr 2019 13:03:00 +0200 Subject: [PATCH] Added ConvertData --- ConvertData.m | 25 +++++++++++++++++++++++++ nonunique.m | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 ConvertData.m diff --git a/ConvertData.m b/ConvertData.m new file mode 100644 index 0000000..a4281c9 --- /dev/null +++ b/ConvertData.m @@ -0,0 +1,25 @@ +function[convertedData]=ConvertData(orgData, varNames, rowNames) +%function[convertedData]=ConvertData(orgData, varNames, rowNames) +% if varnames is not supplied, uses the first column of the table as varNames, and then deletes the column. +% if rowNames is not supplied, the variable names of the input table is used. +% Note that all names are converted to valid variable/row names. In order +% to transpose, the table is converted to a cell array and back. This might +% introduce error, so make sure that the results are as expected! + + +if nargin<2 + varNames=orgData{:,1}; + orgData(:,1)=[]; +end +if nargin<3 + rowNames=orgData.Properties.VariableNames; +end +varNames=matlab.lang.makeValidName(varNames); +rowNames=matlab.lang.makeValidName(rowNames); + +t=table2cell(orgData); +convertedData=cell2table(t'); +convertedData.Properties.VariableNames=varNames; +convertedData.Properties.RowNames=matlab.lang.makeValidName(rowNames); + +end \ No newline at end of file diff --git a/nonunique.m b/nonunique.m index cda8d85..04e8e92 100644 --- a/nonunique.m +++ b/nonunique.m @@ -1,6 +1,6 @@ function [dupes, ind] = nonunique(A) [~, i, ~] = unique(A,'first'); -dupes = A(not(ismember(1:numel(A),i))); +dupes = unique(A(not(ismember(1:numel(A),i)))); ind=ismember(A,dupes); end -- GitLab