finding data points for a graph using a for loop

3 ビュー (過去 30 日間)
nehemiah hofer
nehemiah hofer 2020 年 11 月 28 日
回答済み: KSSV 2020 年 11 月 29 日
I need to create a graph using an equation and data that is in a text file. The values in the data are to be used in the equation top give me data points. I do need to use a for loop. I have been successful in reading in the file and making a matrix with 96 rows and 3 columns. In each row is an x, y, and z values as columns that needs to be put in the equation to get a data point. How do I make a for loop to read in each x, y, and z into the equation and display or store each data point? I should end up with 96 data points to give clarification.
Here's my current code:
txt = readmatrix("ec.txt");
b =70e-9;
a =49e-9;
epsilon_b=1;
s=0.5;
lambda =x*1e-6;
epsilon_c= y+1i*z;
epsilon_s=(1-s)*epsilon_b+s*epsilon_c
I need 96 outputs of Epsilon_s to continue to one final equaton. They can be stored in another 96x1 matrix if that makes things easier.
  2 件のコメント
Walter Roberson
Walter Roberson 2020 年 11 月 29 日
You appear to be working on the same assignment being discussed at https://www.mathworks.com/matlabcentral/answers/667048-for-loop-help-me-plz?s_tid=srchtitle
nehemiah hofer
nehemiah hofer 2020 年 11 月 29 日
It does look close but it appers we are approching it diffrently. I am looking for a way to write a for loop where the for loop moves the row of the matrix and then extracts the three coloums from the row, puts that into an equation to condense the information to one number so i can use that information in another place. I just cant seem to format a for loop in a way that moves down the matrix.Thanks for your help!

サインインしてコメントする。

回答 (1 件)

KSSV
KSSV 2020 年 11 月 29 日
txt = readmatrix("ec.txt");
x = txt(:,1) ;
y = txt(:,2) ;
z = txt(:,3) ;
b =70e-9;
a =49e-9;
epsilon_b=1;
s=0.5;
lambda =x*1e-6;
epsilon_c= y+1i*z;
epsilon_s=(1-s)*epsilon_b+s*epsilon_c

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by