choosing between two array location

my code works when my parced string reads thorugh and places the wanted string in cell 5 but the modify version that i am working on collects two items and places the one i need in cell5 and the unwanted in cell6 and it crashes my script after that.
crashes here due to two cells with data instead of one [] [] [] [] [5] [6] it i may prevent it before getting here from reading string in multiple cells better but after it does fix would be fine as well - im stuck
channel_digits = regexp(channel_data{channel_location}, '\d', 'match');
what may i add so it chooses information in cell5

5 个评论

Jan
Jan 2022-8-10
编辑:Jan 2022-8-10
I do not undestand, what you are asking for. You are mentioning "strings", but I do not see a string in the question. Where does " [] [] [] [] [5] [6]" come from?
Please post a relevant part of the code together with some input data and an explanation of the wanted result.
channel_location = strfind(channel_data, channel_identifier); %%% find which parsed location has channel number
channel_location = find(~cellfun(@isempty,parsed_channel_location)); %%%find exact spot
at this point "channel location' is an matrix of 1x6 and it my old code it would return value in one slot but not i am returning values it slot 5 and 6. but i only need value in slot 5 hence, [] [] [] [] [5] [6] need [] [] [] [] [5] []
channel_digits = regexp(channel_data{channel_location}, '\d', 'match'); %%pulls digits out
digits_concatenated = cellfun(@strcat,channel_digits);
matrix_channel_number = str2num(digits_concatenated);
@Ihaveaquest: The problem gets less clear. It is unclear, what your inputs are and what you want to achieve. What is a "slot"? Again: Where does "[] [] [] [] [5] [6]" occur in your code? Just repeating this piece does not clarify anything. Which variable has this value?
Do you want the 5th cell element only, or the first matching variable, or its index?
Post some input data as Matlab code, which run by copy&paste, and explain exactly, what you want as output. I assume, then the solution is simple, e.g.:
match = contains(channel_data, channel_identifier);
channel = channel_data(find(match, 1));
yes just want the first cell element - sorry i was not very clear i am new to matlab
Please consider using interpunction when writing text. It really helps to understand what you write.
Is your question now solved? Or do you still have a problem?

请先登录,再进行评论。

回答(0 个)

类别

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

产品

版本

R2019a

标签

评论:

Rik
2022-9-28

Community Treasure Hunt

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

Start Hunting!

Translated by