How to make this "for" loop work?

조회 수: 1 (최근 30일)
Ismail Qeshta
Ismail Qeshta 2017년 10월 16일
댓글: Cedric 2017년 10월 16일
Hi, I would like to get all nine possible values of these two sets of s and c vectors. When I try to use for loop, I only get one value. Can anyone please help in making this loop work?
Thank you.
close all; clc; clear all;
s = [1.2535 1.2535 1.2535
c = [0.0 0.5 1.0]
for i=1:100%:5;
for j=1:20%:5;
Formula = s(i)/(sqrt(c(j)));
end
end

채택된 답변

Cedric
Cedric 2017년 10월 16일
편집: Cedric 2017년 10월 16일
s = [1.2535 1.2535 1.2535]
c = [0.0 0.5 1.0]
Formula = zeros( numel(s), numel(c) ) ;
for i=1:3
for j=1:3
Formula(i,j) = s(i)/sqrt(c(j));
end
end
but if you have a recent version of MATLAB, it is simpler to do it using an expansion:
Formula = s.' ./ sqrt(c) ;
  댓글 수: 4
Ismail Qeshta
Ismail Qeshta 2017년 10월 16일
Thank you very much Cedric
Cedric
Cedric 2017년 10월 16일
My pleasure!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Low-Level File I/O에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by