Hello,
I have the following code. The probles is that for every for loop, there are mulitple occurences of firsy in second. So, after every run, L is over written. I would like the indexesfor of anything that matches to be added below the previous output of L, not overwritten. I tried a lot of things but couldn't figure this out. Please help.
for a=1:r
first=test1(a,1);
second=reactionType(:,3);
L=find(strcmp(second,first));
end

댓글 수: 2

Would be real nice if you told what
test1
reationType
is...
Ishita Trivedi
Ishita Trivedi 2018년 12월 31일
they are both cell arrays of varying columns and rows containing mixed data (numbers and strings). test1 is basically my input array that where the 1st column needs to be cross-checked against the 3rd column of reactionType array for any matches. Then I need the index of those matches.

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

 채택된 답변

madhan ravi
madhan ravi 2018년 12월 31일
편집: madhan ravi 2018년 12월 31일

0 개 추천

L=cell(1,numel(r)); % before loop (preallocation)
L{a}.... inside loop
^^^---just add this rest the same
celldisp(L) % after loop (to see the contents of L)

댓글 수: 9

Ishita Trivedi
Ishita Trivedi 2018년 12월 31일
Okay that worked. However, now L is a cell array (1,r) where:
If there is data, the cell is a 11x1 double (for example) and if there is no data, i see [ ] (meaning blank or no matches were found).
Is there a way to trim L to only save cells where there is data and ignore the rest?
madhan ravi
madhan ravi 2018년 12월 31일
편집: madhan ravi 2018년 12월 31일
idx=~cellfun('isempty',L);
L(idx) % this will avoid all the empty arrays
Ishita Trivedi
Ishita Trivedi 2018년 12월 31일
I am sorry for my dumb questions but I am just learning matlab as I work on this. So I don't quite understand where to add this line?
madhan ravi
madhan ravi 2018년 12월 31일
Don't be sorry , at the end of the code.
Ishita Trivedi
Ishita Trivedi 2018년 12월 31일
This worked perfectly. Thank you so much.The three things I am struggling with in matlab is learning how to use textscan, format (when using text scan) and cellfunc properly.
I am sure it will be easier once I get better at this. But thank you for helping.
madhan ravi
madhan ravi 2018년 12월 31일
Anytime :) , read the documentation of textscan() it has plenty of examples.
Ishita Trivedi
Ishita Trivedi 2018년 12월 31일
Thank you!
I actually have a follow up. When I store the index of all matches in L{a} - in column 2 of L{1,1} (for example),how can I also store the input value from test_1 that is being compared to the master library reactionType inside for loop?
index comes from master library and input from test_1.
madhan ravi
madhan ravi 2018년 12월 31일
just preallocate as shown in the answer and follow it
Ishita Trivedi
Ishita Trivedi 2018년 12월 31일
Hello,
The problem I am encountering here is how to have string at L{1,1}(1,2) while L{1,}(1,1) is a number?
I keep getting NaN.

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

추가 답변 (0개)

카테고리

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

제품

릴리스

R2018b

질문:

2018년 12월 31일

댓글:

2018년 12월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by