how to create matrices efficiently

Hi!
let's say I have 10 different angles. So I have a1, a2, a3, ... a10. I need to calculate 10 different 2x2 matrices depending those angles and save them. So my matrices will be [cos(a1), sin(a1); sin(a1), -cos(a1)] and so on. Question is how I can make those matrices without writing all 10 matrix by hand? I've tried make those by for loop and I think my problem is that I need multiple matrices instead vectors.

댓글 수: 2

Azzi Abdelmalek
Azzi Abdelmalek 2013년 9월 21일
This is not clear
Roger Stafford
Roger Stafford 2013년 9월 21일
Just a note of caution. In case those 2x2 matrices were intended to be rotation matrices by the angles a1, a2, ..., the signs are wrong in the second column.

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

 채택된 답변

per isakson
per isakson 2013년 9월 21일
편집: per isakson 2013년 9월 21일

0 개 추천

Here is a start
>> f = @(a) [cos(a), sin(a); sin(a), -cos(a)];
>> f(pi)
ans =
-1.0000 0.0000
0.0000 1.0000
>>
where
f = @(a) [cos(a), sin(a); sin(a), -cos(a)];
Search the help for "Anonymous Functions"

추가 답변 (1개)

Kasper
Kasper 2013년 9월 23일

0 개 추천

That helped so much!! Thank You!

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2013년 9월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by