필터 지우기
필터 지우기

Help with Vectors and For Loops and determining whether it's negative or positive?

조회 수: 1 (최근 30일)
Iterate through a vector A, using a for loop and create a new vector B, containing logical values. The new vector should contain true for positive values and false for all the other values. For example, if:
A = [-300 2 5 -63 4 0 -46]
Then the result should be
B = [false true true false true true false]
The program should prompt the user to enter the vector. The input vector entered by the user can be of ANY size
The program should output both the original vector and the vector with logical values.
So basically I need to allow the user to input a variable, then use a for loop to check each of the variables to see whether they are positive? v=input('Please input your vector: \n') that's as far as I got. Thanks ahead for your help!!
  댓글 수: 1
Stephen23
Stephen23 2014년 10월 8일
Getting started on Homework can be tough... but there are lots of resources out there on the internet, and part of your job as a student is to learn how to find and use information.
If you have specific problems or misbehaving code, come back to MATLAB Answers, show us what you wrote, and we will help you out. Enjoy learning about MATLAB, and good luck with the homework!

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

채택된 답변

Rick Rosson
Rick Rosson 2014년 10월 8일
편집: Rick Rosson 2014년 10월 8일
doc for
doc numel
doc size
docsearch('"logical indexing"')
doc false
doc true
docsearch('"preallocating arrays"')
doc disp
doc fprintf

추가 답변 (0개)

카테고리

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