defining value in two cells?

Hi,
I have an excel file which contains 4 columns. First column is time based on seconds and the other three are my function. How is it possible to find a time for specific value in the time column? let me give an example:
I want to define where is this value in the second column: 0.7636 and I found it manually in excel that it is located in time column between 6960[s]-7020[s].
So, if I have for example a couple of values, and also considering different functions then it is difficult to do it manually.
I hope to hear your support. Thanks Sepideh

 采纳的回答

See the FAQ: http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F, but I would not recommend comparing the vector to find that value exactly - I'd use the min function:
data = rand(3000,2); % Sample data - replace with your own.
targetValue = 0.7636; % The desired value you hope to find.
% Get differences between actual values and desired value.
differences = abs(data(:, 2) - targetValue);
% Find the row with the closest value.
[~, row] = min(differences);
% Extract the data from that closest row.
targetTime = data(row, 1)
closestValue = data(row, 2)

3 个评论

Hi, I am new to Matlab I wrote exactly your code but with changing the first row: data = dataset('xlsfile', 'Q1.xlsx') targetValue = 0.7636; % The desired value you hope to find. % Get differences between actual values and desired value. differences = abs(data(:, 2) - targetValue); % Find the row with the closest value. [~, row] = min(differences); % Extract the data from that closest row. targetTime = data(row, 1) closestValue = data(row, 2)
then I got this error:"Undefined function 'minus' for input arguments of type 'dataset'."
How is it possible to solve this problem? Is it related to the excel file?
Hope to hear your answer Thanks Sepideh
Hi,
I solved this problem. Many thanks for help
You're welcome. I recommend readtable(), or readxls() instead of dataset().

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by