Substituting values to/from a cell array

Suppose I have 2 cell array:
a={4 1 3 5; 5 5 1 4}
b={*5* 1 3; 1 3 4}
How can I substitute the values in cell array a(column 2:4) using values from b(column 1:3) that corresponds to the values in a(column 2 and 3)?
The resultant matrix should be this
resultant={4 1 3 4
5 5 1 3}
P/S: This is a very simple example from the code which I'm working on at the moment. I would like to know how to get about it and I will do the necessary adjustments. Thank you.

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 9월 9일

1 개 추천

a={4 1 3 5; 5 5 1 4}
b={5 1 3; 1 3 4}
a(:,2:4)=b(:,1:3)

댓글 수: 3

Amit Nambiar
Amit Nambiar 2013년 9월 9일
편집: Amit Nambiar 2013년 9월 9일
Hi Azzi, Why has he used '{}' type of brackets to declare arrays, how is this different from '[]' brackets?
Jan
Jan 2013년 9월 9일
See: help cell. With curly braces the elements can have different size and type, while with square brackets, all elements must have the same type and matching dimensions (roughly spoken - there is an automatic type conversion also for convenience).
Amit Nambiar
Amit Nambiar 2013년 9월 9일
Oh... now I understand...Thank you Jan Simon!

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by