필터 지우기
필터 지우기

Just learning matlab question

조회 수: 2 (최근 30일)
Robert
Robert 2012년 2월 2일
I just started taking a MATLAB class at school and we have a problem to do. I am a little stuck on something and I cannot find an answer in my notes or the book. Tha basic premise is this: I have one value call it x = 2 I have a set of distances, 1 2 3 4 5 and a formula which is M= x * distance. I just posted this in the newsgroups...I Am not sure wha tis more effective since I just started here.
We need to do the calculation which I did. here M would be 2 4 6 8 10 Then if M is greater than say 5 have matlab say one thing if less than 5 say another. I cant seem to get matlab to recognize my if statements. I dont want to be too specific because I dont want to just get the answer but the way to do it. Any help would be great. Thanks
Bob

채택된 답변

Geoff
Geoff 2012년 2월 3일
It's hard to answer this without giving you the answer... =) But here goes an attempt...
You can do boolean operations on a vector or matrix just as you would on a scalar value. Just compare the matrix to a value and you will get a matrix of booleans back.
That's the best I can offer without saying exactly what you might do. If you want clarification, feel free to ask =)
  댓글 수: 3
Geoff
Geoff 2012년 3월 30일
Sweet as. Trial and error is the best way to learn, with a little guidance when you get stuck. =) I'm a self-taught programmer via exactly that approach. There was no internet to ask questions, so I just experimented until I worked it out, and read code in books to try and understand how computers work. It's amazing what you learn by dabbling that you don't learn by being shown! Needless to say, it's frustrating to see some people here, faced with one of the friendliest and most harmless programming languages around, freaking out and being afraid to just try things out (or pay attention to what the error messages are saying). Glad that you are trying harder than that. =) Keep it up.
Walter Roberson
Walter Roberson 2012년 3월 30일
You had books? Why, when I was learning programming, we...
Urrr, actually we _did_ have books, but the books back then assumed you had an intense interest in the bus cycle diagrams, the instruction-by-instruction timing and how it varied for each addressing mode, and of the inertial properties for the paper tape reader. User manuals were a few years off yet.
If I recall correctly, in those days, the largest community college had 5 computers, total, including the finance system (my father gave me a tour of them; I gather he had repaired 3 of them.)

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2012년 2월 3일
Use logical indexing. For example,
M5 = M > 5;
M(M5) = (M(M5) - 1) / 2; %the one case
M(~M5) = M(~M5) + 3; %the other case

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by