Info
この質問は閉じられています。 編集または回答するには再度開いてください。
Puling values from a matrix?
1 回表示 (過去 30 日間)
古いコメントを表示
Let me explain:
1) I have a table of 20 values, ranging from 0 to 1, in MATLAB.
2) I also have a matrix, with the first column being 20 values long.
Those values from the first table? The 'ones' represent the values I need to pull from the matrix's first column. I need the positions of the ones in the first table, and those positions would tell me the row number in the matrix of the values I need to pull.
How do I do this?
This is what I have so far:
check_in = input('Enter check-in date:','s');
date_cell_array = strsplit(check_in);
month = date_cell_array{1};
d_string = date_cell_array{2};
y_string = date_cell_array{3};
d = str2num(d_string)
y = str2num(y_string);
m = MonthToNum(month);
table = availability(d,:);
positions = find(table==1);
When I enter the date 'April 5 2016' as an example
'Table' gives me this:
1 1 1 0 1 0 1 1 1 1 1 1 1 1 0 1 0 1 1 1
And 'positions' gives me this:
1 2 3 5 7 8 9 10 11 12 13 14 16 18 19 20
1 件のコメント
回答 (1 件)
Walter Roberson
2016 年 5 月 1 日
編集済み: Walter Roberson
2016 年 5 月 1 日
column_to_extract = 1;
value_to_match = 1;
mask = ismembertol(table,value_to_match);
ExtractedValues = MatrixToPullFrom(mask, column_to_extract);
The ismembertol is used to find values "sufficiently close" to the target value. You did mention you were using floating point values between 0 and 1, and floating point values should seldom be compared for exact equality.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!