フィルターのクリア

function to display name

7 ビュー (過去 30 日間)
shir meir
shir meir 2021 年 4 月 7 日
回答済み: Sajid Afaque 2021 年 4 月 7 日
hey, i'm trying to create a function that will find from a structure all the car that have horsepower above 200 and display their model names from the structure.
But when I buit it, its show the names only with a space and blank names between them.
can you help me fix it?
I used the carsmall.mat database
function result = best_horsepower2(stru);
for i=1:size(stru.Horsepower,1);
if stru.Horsepower(i,:)> 200;
big(i,:)= stru.Model(i,:);
result=big;
end
end
  2 件のコメント
Sajid Afaque
Sajid Afaque 2021 年 4 月 7 日
please provide more details
shir meir
shir meir 2021 年 4 月 7 日
this is
when I run the current function it show it like that... with the blank space

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

採用された回答

Sajid Afaque
Sajid Afaque 2021 年 4 月 7 日
that is because while storing the result in big you are using the index i
please try below code it might help
function result = best_horsepower2(stru);
%intialise a count vector for storing the results hence you can avoid blank
%space
count = 1;
for i=1:size(stru.Horsepower,1);
if stru.Horsepower(i,:)> 200;
big(count,:)= stru.Model(i,:);
result=big;
count = count + 1;
end
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by