Clear Filters
Clear Filters

how to refer an element in a column to related a value in another cloumn?

1 view (last 30 days)
I have a data set as attached. 6th column represent the time. I want to find the value in the 2nd Column related to "GX" in 1st column at the time "11:49:29 " I appreciate if anyone can suggest a method for this?
Thanks in advance.

Answers (1)

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH on 7 Nov 2016
fileID = fopen('text.txt');
C = textscan(fileID,'%s %s %s %s %s %s %s','Delimiter',',');
fclose(fileID);
C=[C{:}];
value=C{and(strcmp(C(:,1),'GX'),cell2mat(cellfun(@(x) ~isempty(strfind(x,'11-49-29')),C(:,6),'UniformOutput', false))),2};
disp(value)
  1 Comment
Nadeera Gunartna
Nadeera Gunartna on 13 Nov 2016
Edited: Nadeera Gunartna on 13 Nov 2016
Thanks for the answer. but when I run it there is an error called "Error using horzcat Dimensions of matrices being concatenated are not consistent. " So, I have to separate numeric values and character values as follows for the calculations.
rawNumericColumns = raw(:, [2,3,4,5,6]);
rawCellColumns = raw(:, 1);
v = rawCellColumns(:, 1);
D1 = cell2mat(rawNumericColumns(:, 1));
D2 = cell2mat(rawNumericColumns(:, 2));
D3 = cell2mat(rawNumericColumns(:, 3));
D4 = cell2mat(rawNumericColumns(:, 4));
t = cell2mat(rawNumericColumns(:, 5));
now I can not combine these all as one ( like you suggest as "C"). so, is there anyway to refer the values in numeric columns related to that character array values?

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!