how do i "re attach" string columns to data columns for identification?

when i input data, matlab always separates my string data( column headers and row id's) from the data it represents...i have been able to work around this because matlab keeps everything in place and it is easy to slap them back together outside of matlab... but i am working with data brushing and graphs, the databrushing retrieves the data values but not the row id...so how do i "link' my data with its original identifiers in Matlab???

Answers (1)

If I understand you correctly, here is a small example:
x = rand(100,1);
y = rand(100,1);
names = char(randi(100,[100 3])+50); %random names
scatter(x,y);
%Do the brushing
%
% Brush your selection and then right-click, create variable, name it
% xbrush
%
[~,idx] = ismember(xbrush,[x y],'rows'); %locate them
names(idx) %extract names

11 Comments

thanks for your input sean, i believe i understand your code except the "~" in the 2nd to last line...i will give it a try...for some reason i was thinking "cell arrays" may be the answer
Well the cell array could hold your strings rather than the char that I had. How do you have the strings stored now?
To convert my names to a cell, just write
names = cellstr(names)
so my data is made up of 12 columns, the 1st column is made up of identifiers for the values across that row. evrytime i input into matlab, it separates the numeric data from the column of row identifiers. the "data" file consists of the columns of number values and the "textdata" file consists of the row id's which are characters, like, jb001,or GABD7...iv'e been able to work around this by keeping my data in order. but now i am creating scattterplots, and brushing the graph to extract outliers on the plots...the problem is that i only get back the values and not the row identifiers that they represent...cell array didn't work because i cannot plot only parts of the cell, i have to create variables from each column, plot them, extract and id outliers...i am trying your code now...
sorry sean but your code is coming back unbalanced...i have 3 columns, all the same length A,B and id( column with id's) i brushed my graph and created a new variable "ans" i coded;
[~,idx]=ismember(ans,[A,B],'rows');
i got back unbalanced statement
Don't use ans!! It's overwritten every time you do anything. Try my example first. Then change it to use idx (indices corresponding to brushed points) into your column of ids.
to clarify...an example of my data... column1= john001, jim5, jane09. column2=4.5, 2, 1.5. column3= 8.1,7.0, 4. i create a scatter plot from columns 2 and 3 and brush the graph. i get back values, but i need the corresponding name from column 1...i will work with your example some more...
So data is a cell array?
Are you using R2013b by any chance?
nosir, its R2008b...as to previous example using 3x3 dataset--so i input the data as shown, matlab auto separates the data...1 file "data' contains numeric values in a matrix. the 2nd file, 'textdata' contains a column of "row identifiers" AND a row of column identifiers, i amnow wondering if i should remove that row of column headers...so that the id column is = to the value columns...duh
also the codeline, names=...came back unbalanced, when i tried you example
iam looking into how to work with cell array data...
Just attach your file and the code you're using right now.

This question is closed.

Asked:

on 19 Dec 2013

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!