フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Determine whether file value is within certain integer of an array value

1 回表示 (過去 30 日間)
g
g 2019 年 10 月 22 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I have some arbitrary files in a directory "my_directory":
file_1002.txt
file_1012.txt
file_1023.txt
file_2045.txt
each with some value.
In Matlab, I have an array of values, call it "my_array"
1000
1010
2055
I want to check whether the file value is within 10 of a value in my array. Then, if so, I want to rename the file.
For example, file_1002.txt has a value of 1002, which is within 10 of values in my_array (namely 1000 and 1010). Therefore, file_1002.txt will be renamed file_1002_new.txt. Likewise, for 1012 and 2045. However, file_1023.txt has a value of 1023, which is not within 10 of any values in my_array, so file_1023.txt does not need to be renamed.
How could this scheme be accomplished? I am dealing with many files in my_directory and many values in my_array, so a quicker solution would be more optimal. Thanks!

回答 (1 件)

David Hill
David Hill 2019 年 10 月 22 日
Load text into a variable say T and make sure it is a number.
if sum(my_array>(T-10)&my_array<(T+10))%repeat for as many files as you have
%save renamed file
end

この質問は閉じられています。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by