Can I perform subtraction using cell arrays?

조회 수: 12 (최근 30일)
Yao
Yao 2012년 10월 13일
Hi all,
I have 2 sets of numbers which i would like to subtract them and compare their values and perform a counter loop.
Is there any function I can make use of to do that? Thanks
for example I have these 2 sets of numbers which I need to subtract each value and compare:
filteredAreaSample =
3594 3627 3626 3625 3610
filteredAreaStudent =
3648 3621 3613 3620 3626
  댓글 수: 1
Matt J
Matt J 2012년 10월 14일
편집: Matt J 2012년 10월 14일
It really doesn't make sense for you to maintain data like this in cell arrays. Data like this can be held in simple matrices, making them very simple (and CPU optimized) to subtract
Differences = filteredAreaSample - filteredAreaStudent
Cell arrays are meant mainly for situations where you have arrays of different sizes or types, e.g.,
mycell={rand(5), eye(3),'dog','cat'},
or when you want to perform comma-separated list operations, e.g.,
[A,B,C,D]=deal(mycell{:});

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

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2012년 10월 14일
편집: Azzi Abdelmalek 2012년 10월 14일
A ={ 3594 3627 3626 3625 3610}
B ={ 3648 3621 3613 3620 3626}
res=cellfun(@(x,y) y-x,A,B)
  댓글 수: 10
Yao
Yao 2012년 10월 14일
Hi sir, i tried your method and it works.
Thank you so much for your help.
Lets say if I want to build a counter that says if res is larger then 100; add 1 if res is smaller then 100 add 0, how should I do it? In this case, the output are all zeros, so I should show my results as 20. Thanks again for your help
out = Difference >100
out =
Columns 1 through 12
0 0 0 0 0 0 0 0 0 0 0 0
Columns 13 through 20
0 0 0 0 0 0 0 0
Azzi Abdelmalek
Azzi Abdelmalek 2012년 10월 14일
편집: Azzi Abdelmalek 2012년 10월 14일
Can you be more clear, you have your array Difference, what test do you want to do? And I think you should accept the answer that correspond to your expectation then post another question.

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

추가 답변 (1개)

Wayne King
Wayne King 2012년 10월 13일
편집: Wayne King 2012년 10월 13일
out = cellfun(@minus,filteredAreaSample,filteredAreaStudent);
  댓글 수: 1
Yao
Yao 2012년 10월 14일
Hi Sir,
I got this error "Function name must be a string."

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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by