How to get matlab to automatically read csv data with a manual input?

6 ビュー (過去 30 日間)
brian donnelly
brian donnelly 2016 年 10 月 27 日
編集済み: Walter Roberson 2016 年 10 月 28 日
I have a piece of code written that analyses (numerical) patient data e.g. age. I am using an if statement with a number of sub elseif statements to generate an output. The data to be analysed will ultimately produce a False / Positive output. The code is working but i want matlab to read the data automatically. I have used csvread and am attempting to introduce a for loop but this is where i get stuck. Any help would be grateful.

回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 10 月 27 日
Example:
num = csvread('YourFile.txt');
numrows = size(num, 1);
ticket_prices = zeros(numrow, 1); %the output variable
for rownum = 1 : numrows
thisrow = num(rownum, :);
age = thisrow(7); %for example, if the age were in column 7 of the row
if age < 3
ticket_price = 0;
elseif age <= 5
ticket_price = 4.99;
elseif age <= 13
ticket_price = 10.99;
elseif age <= 18
ticket_price = 15.84;
else
ticket_price = 206.18;
end
ticket_prices(thisrow) = ticket_price;
end
  13 件のコメント
brian donnelly
brian donnelly 2016 年 10 月 27 日
Hi Walter,
Could I ask you to explain that in a bit more detail. I added the 'else' case to -> else result = ('Unconfirmed');

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

カテゴリ

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