Hello guys ! I need to import from a .csv and display only 10 numbers(bold ones) preceded by a certain 3 numbers(underlined) string, so this 10 numbers will we found with other value in a column more than one time but only the 3 number that precede are the same everytime. The column can contain 50 or more repetitive string of 3 numbers 21 22 23 with different afferent prices below.
The 3 numbers repetitive represent lot number and the following represent prices.
T = readtable('prices.csv');
B = T(:,2);
Example column no 2 from csv:
25.12
45.13
21
22
23
65.55
45.44
42.66
78.56
45.88
42.66
89.78
88.55
45.55
79.65
45.66
123.45
259.45
21.56
42.53
12.49
21
22
23
25.12
45.13
89.78
88.55
45.55
79.65
45.66
45.44
42.66
78.56
45.88
45.55
79.65
45.66
45.44
42.66
78.56
45.88
Thanks!

 채택된 답변

Ameer Hamza
Ameer Hamza 2020년 6월 13일

0 개 추천

Try this
M = [
25.12
45.13
21
22
23
65.55
45.44
42.66
78.56
45.88
42.66
89.78
88.55
45.55
79.65
45.66
123.45
259.45
21.56
42.53
12.49
21
22
23
25.12
45.13
89.78
88.55
45.55
79.65
45.66
45.44
42.66
78.56
45.88
45.55
79.65
45.66
45.44
42.66
78.56
45.88];
tf = ismember(M, [21; 22; 23]);
idx = find(diff(tf)>0)+1+(0:12);
vals = reshape(M(idx).', [], 1);
Result
>> vals
vals =
21.0000
22.0000
23.0000
65.5500
45.4400
42.6600
78.5600
45.8800
42.6600
89.7800
88.5500
45.5500
79.6500
21.0000
22.0000
23.0000
25.1200
45.1300
89.7800
88.5500
45.5500
79.6500
45.6600
45.4400
42.6600
78.5600

댓글 수: 3

Cristian Martin
Cristian Martin 2020년 6월 13일
Amza I want this to be a script used by many employees. So it must to be unique. I have to modify only the lot numbers, the 3 one's that are every time repeats.
"So it must to be unique". How do you define that? The code only have 3 lines
tf = ismember(M, [21; 22; 23]);
idx = find(diff(tf)>0)+1+(0:12);
vals = reshape(M(idx).', [], 1);
You can write it as a function
function y = get10vals(M, indicators)
tf = ismember(M, indicators);
idx = find(diff(tf)>0)+1+(0:12);
vals = reshape(M(idx).', [], 1);
end
and then call it like this
M = % matrix
vals = get10vals(M, [21; 22; 23]);
Cristian Martin
Cristian Martin 2020년 6월 13일
Thanks a lot Amza, that's ok.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품

릴리스

R2016b

질문:

2020년 6월 13일

댓글:

2020년 6월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by