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

2 次查看(过去 30 天)
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.

回答(1 个)

JESUS DAVID ARIZA ROYETH
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 个评论
Nadeera Gunartna
Nadeera Gunartna 2016-11-13
编辑:Nadeera Gunartna 2016-11-13
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?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Licensing on Cloud Platforms 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by