フィルターのクリア

Trouble labeling x and y axis

4 ビュー (過去 30 日間)
Ryan
Ryan 2024 年 4 月 13 日
回答済み: Ryan 2024 年 4 月 13 日
So I am very new to matlab overall and I have to make a bar graph for a project with labeled a x and y axis. Everytime I try to run it, I get the error message: Index exceeds the number of array elements. Index must not exceed 1.
I also get an error in the line where I have the xlabel command, it's just the line in red text and it does not tell me what the problem is.
Here is the entire line of code since I do not know exactly where I messed up in this:
%%% Task 1: Introduction, and functionality%%%
disp('Hello world!')
%%% Task 2: Loading user data%%%
data1=readtable("user1.csv");
data2=readtable("user2.csv");
data3=readtable("user3.csv");
data4=readtable("user4.csv");
data5=readtable("user5.csv");
data6=readtable("user6.csv");
data7=readtable("user7.csv");
data8=readtable("user8.csv");
data9=readtable("user9.csv");
data10=readtable("user10.csv");
%%% Task 3: Basic analysis%%%
A_1 = mean(data1,"all");
A_2 = mean(data2,"all");
A_3 = mean(data3,"all");
A_4 = mean(data4,"all");
A_5 = mean(data5,"all");
A_6 = mean(data6,"all");
A_7 = mean(data7,"all");
A_8 = mean(data8,"all");
A_9 = mean(data9,"all");
A_10 = mean(data10,"all");
B_1= min(data1);
B_2= min(data2);
B_3= min(data3);
B_4= min(data4);
B_5= min(data5);
B_6= min(data6);
B_7= min(data7);
B_8= min(data8);
B_9= min(data9);
B_10= min(data10);
C_1= max(data1);
C_2= max(data2);
C_3= max(data3);
C_4= max(data4);
C_5= max(data5);
C_6= max(data6);
C_7= max(data7);
C_8= max(data8);
C_9= max(data9);
C_10= max(data10);
User=["User 1";"User 2";"User 3";"User 4";"User 5";"User 6";"User 7";"User 8";"User 9";"User 10"];
Gap_count=[16;25;16;20;6;23;37;6;21;41];
Average= [A_1;A_2;A_3;A_4;A_5;A_6;A_7;A_8;A_9;A_10;];
Minimum= [B_1;B_2;B_3;B_4;B_5;B_6;B_7;B_8;B_9;B_10;];
Maximum= [C_1;C_2;C_3;C_4;C_5;C_6;C_7;C_8;C_9;C_10;];
Basic_stat_analysis = table(User,Gap_count,Average,Minimum,Maximum);
disp(Basic_stat_analysis)
%%Task 5: Initial Visualization%%
user_1 = table2array(data1);
figure;
bar(user_1);
title('User 1 data')
xlabel('Number of gaps')
ylabel('Gap duration')

回答 (2 件)

Steven Lord
Steven Lord 2024 年 4 月 13 日
Do you have a variable named xlabel in the workspace? If you do, you cannot call the xlabel function. Clear or rename the variable. To check if you have a variable, show what this displays:
which xlabel
/MATLAB/toolbox/matlab/graphics/axis/xlabel.m
  1 件のコメント
Ryan
Ryan 2024 年 4 月 13 日
So I was actually able to solve the issue by myself, I basically made a mistake at the beginning when I started the project. This code is part of a bigger collection of .m files and I accidentaly forgot to make a path for it to the rest of the collection. Now the code works fine and I am able to make an x and y axis.

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


Ryan
Ryan 2024 年 4 月 13 日
So I was actually able to solve the issue by myself, I basically made a mistake at the beginning when I started the project. This code is part of a bigger collection of .m files and I accidentaly forgot to make a path for it to the rest of the collection. Now the code works fine and I am able to make an x and y axis.

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by