How do I solve this error?: Matrix out of range for deletion (2024)

27 views (last 30 days)

Show older comments

Tessa Nefouse on 2 Aug 2024 at 16:27

  • Link

    Direct link to this question

    https://jmaab.mathworks.com/matlabcentral/answers/2142521-how-do-i-solve-this-error-matrix-out-of-range-for-deletion

  • Link

    Direct link to this question

    https://jmaab.mathworks.com/matlabcentral/answers/2142521-how-do-i-solve-this-error-matrix-out-of-range-for-deletion

Commented: Andres Adam on 2 Aug 2024 at 22:46

Open in MATLAB Online

Can someone help me to figure out why I am out of range for deletion with this? This code was first used with data that had multiple values in the matrix (i.e. "carbclay" was a matrix with 4 values), but now I'm only doing it with one value, so maybe that's why it's not working? I have gotten a lot of help with this so I don't quite understand it fully, forgive my lack of knowledge when it comes to calling things the right name, hope someone can understand what's wrong:( The goal of the code is to be able to leave off legend entries if any of the data that I want to plot is missing from my table.

carbclay=[rocktypes(1)]; missingdata1=[];

np = 0;

hp = [];

legtxt = {};

i = find(string(TAllData.gen_rock_type)==carbclay);

if any([sum(isnan(TAllData.a_b(i)))==length(i),sum(isnan(TAllData.temp(i)))==length(i)])

missingdata1=[missingdata1,i];

else hp(end+1) = scatter(TAllData.temp(i),TAllData.a_b(i),120,c1,'filled','o','MarkerFaceAlpha',0.7);

end

carbclay(missingdata1)=''; %The error happens here for some reason, and then the legend does not show up

legend(hp,legtxt,'Location','northeastoutside');

Error Message:

Matrix index is out of range for deletion.

Error in ScriptForPlots_RFD (line 1507)

carbclay(missingdata1)='';

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

Answers (1)

Andres Adam on 2 Aug 2024 at 16:47

  • Link

    Direct link to this answer

    https://jmaab.mathworks.com/matlabcentral/answers/2142521-how-do-i-solve-this-error-matrix-out-of-range-for-deletion#answer_1494076

  • Link

    Direct link to this answer

    https://jmaab.mathworks.com/matlabcentral/answers/2142521-how-do-i-solve-this-error-matrix-out-of-range-for-deletion#answer_1494076

There is a lot of information missing in that piece of code, so it's very hard to find what is the actual issue and how to resolve it.

At a high-level glance, you are defining carbclay to be a scalar: 1 element. But you are trying to access the position "missingdata1". The position "missingdata1" is informed from examining the array "TAllData.gen_rock_type".

There is no indication that TAllData.gen_rock_type is the same length as carbclay, so that is a dangerous assignment to do.

2 Comments

Show NoneHide None

Tessa Nefouse on 2 Aug 2024 at 17:11

Direct link to this comment

https://jmaab.mathworks.com/matlabcentral/answers/2142521-how-do-i-solve-this-error-matrix-out-of-range-for-deletion#comment_3227856

  • Link

    Direct link to this comment

    https://jmaab.mathworks.com/matlabcentral/answers/2142521-how-do-i-solve-this-error-matrix-out-of-range-for-deletion#comment_3227856

Open in MATLAB Online

Yes, there is a lot of info missing, I just thought it would be too much to include my entire code, so I just did this. But I am not sure what is and what isn't important to include :(. I will include the old code for when carbclay consisted of more than one value.

In my new code, I don't have a loop because carbclay is only one element, so I have deleted the 'j'. But since I reference j in the line 'legtxt{end+1} = carbclay{j}', I am struggling to figure out what to replace that with in my newer code. Does this give any more context?

[rocktypes,rocki] = unique(TAllData.gen_rock_type); %TAllData is my large data set, gen_rock_type is a column name that includes 13 different rock types

Unable to resolve the name 'TAllData.gen_rock_type'.

carbclay=[rocktypes(1),rocktypes(8),rocktypes(13)]'; %there are 13 elements in the rocktypes array, im assigning 3 of them to the category 'carbclay'

for j = 1:length(carbclay)

i = find(string(TAllData.gen_rock_type)==carbclay(j) & (TAllData.temp<=25));

if any([sum(isnan(TAllData.a_b(i)))==length(i),sum(isnan(TAllData.eff_Normal(i)))==length(i)])

missingdata1=[missingdata1,j];

else

hp(end+1) = scatter(TAllData.eff_Normal(i),TAllData.a_b(i),150,'filled','pentagram','MarkerFaceAlpha',0.7);

legtxt{end+1} = carbclay{j};

end

end

Andres Adam on 2 Aug 2024 at 22:46

Direct link to this comment

https://jmaab.mathworks.com/matlabcentral/answers/2142521-how-do-i-solve-this-error-matrix-out-of-range-for-deletion#comment_3228116

  • Link

    Direct link to this comment

    https://jmaab.mathworks.com/matlabcentral/answers/2142521-how-do-i-solve-this-error-matrix-out-of-range-for-deletion#comment_3228116

Open in MATLAB Online

I see you want to plot as a scatter the values of TAllData that are also in carbclay, and that do not give NaN in certain properties as defined by the first if clause.

You are currently wondering how to change the code to consider the case where carbclay is a scalar.

Short answer: you do not have to change anything. If the code runs OK for carbclay as an array, I don't see why it won't be applicable to arrays of length 1.

Longer answer: if you want to restructure the code anyway, legtxt and carbclay are scalars, they do not need to have {}. Also watch out for missingdata1. It is not being allocated before its use inside the double loop.

Additionally: your need to store text as legtxt might be unnecessary. Consider using the "DisplayName" property of scatter:

https://www.mathworks.com/help/matlab/ref/matlab.graphics.chart.primitive.scatter-properties.html#d126e1507255

hp(end+1) = scatter(TAllData.eff_Normal(i),TAllData.a_b(i),150,...

'filled','pentagram','MarkerFaceAlpha',0.7...

'DisplayName',carbclay{j});

legend

Sign in to comment.

Sign in to answer this question.

See Also

Tags

  • matrix
  • table
  • legend

Products

  • MATLAB

Community Treasure Hunt

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

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


How do I solve this error?: Matrix out of range for deletion (5)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Contact your local office

How do I solve this error?: Matrix out of range for deletion (2024)

FAQs

How to delete a matrix in Matlab? ›

= MLDeleteMatrix( var_name ) deletes the named matrix from the MATLAB® Workspace. Use this syntax when working directly in a worksheet.

How do you delete data in Matlab? ›

Select MATLAB > General and in the Deleting files section, select from the available options. Alternatively, you can use the recycle function. When file recycling is on, the delete function moves deleted files to a location specific to the platform: Windows® — Recycle bin.

How do I delete a listing on matrix? ›

Matrix
  1. In Matrix, go into the listing you are wanting to cancel and click the blue Edit pen.
  2. Under Select Form, click on Change to Canceled.
  3. Under Status Information/New Status select Canceled. ...
  4. In Paragon, go to Listings, and under the Maintain section, select Listings.
Jun 6, 2023

Can you delete in MATLAB? ›

Swipe left on the command you want to remove. Tap Delete. To remove multiple items, select the commands and figures you want to remove and tap the Action button, and then tap Delete.

How do I remove a value from a dataset? ›

If you want to get rid of just the data and nothing else, you can use the command drop all. The drop command is used to remove variables or observations from the dataset in memory. If you want to drop variables, use drop varlist. If you want to drop observations, use drop with an if or an in qualifier or both.

How to trim a matrix in MATLAB? ›

B = trimdata( A , m ) trims A to size m by removing elements from the trailing side of A . For example, for a scalar size m : If A is a vector, then trimdata(A,m) trims A to length m . If A is a matrix, table, or timetable, then trimdata(A,m) trims A to have m rows.

How do you delete entries in MATLAB? ›

deleteEntry( sectionObj , entryName ,'DataSource', dictionaryName ) deletes an entry that is defined in the data dictionary DictionaryName . Use this syntax to uniquely identify an entry that is defined more than once in a hierarchy of referenced data dictionaries.

How do I delete a matrix room? ›

Delete rooms and leave rooms

If the last person in the room leaves, the room is archived for 7 days. After that, is it deleted permanently. As room administrator, you should “kick” (remove) all members of the room first. Then you should leave the room as the last person to initiate the later deletion by the server.

How do you delete a figure in MATLAB? ›

How to Delete Graphics Objects
  1. delete(gca) If you want to delete multiple objects, pass an array of handles to delete . ...
  2. f = figure; y = rand(1,5); bar(y) The figure now contains axes and bar objects. ...
  3. close(f) MATLAB® deletes each object.

How do you delete a matrix user? ›

Removing users, rooms and content

If you're using Element, when you go to view more information about a particular user there will be a 'deactivate user' button (shown below) which does this for you. Note that only users on your homeserver can be deactivated, provided you have the admin permissions to do so.

Top Articles
Universal Edition – Noten und Bücher
Cookie Clicker Math Playground
Gasbuddy Joliet
Msc Open House Fall 2023
Coverwood Terriers For Sale
Costco Fuel Price Today Near Me
7076605599
8x20, 8x40 Shipping containers storage container for rent or sale - general for sale - by dealer - craigslist
Redbox Locations Walmart
Hailie Deegan News, Rumors, & NASCAR Updates
Relic Gate Nms
888-490-1703
102 Weatherby Dr Greenville Sc 29615
Red Dead Redemption 2 Legendary Fish Locations Guide (“A Fisher of Fish”)
Best Pedicure Nearby
Martimelons
Inside the Rise and Fall of Toys ‘R’ Us | HISTORY
Summoner Weapons Terraria
Walking through the Fire: Why nothing stops Jesus’ love for you - Ann Voskamp
Craigslist Manhattan Ks Personals
Kroger Liquor Hours
Sufficient Velocity Quests
Experience the Convenience of Po Box 790010 St Louis Mo
Alvin Isd Ixl
Accuweather Mold Count
Pole Barns 101: Everything You Need to Know - Big Buildings Direct
Scenes from Paradise: Where to Visit Filming Locations Around the World - Paradise
What Does FYP Mean on TikTok?
Moss Adams Client Portal
Craigslist Apts Near Me
Vision Government Solutions Stamford Ct
Fortnite Fap Hero
Dayinew
Watch ESPN - Stream Live Sports & ESPN Originals
Andhrajyoti
Roblox Roguelike
Journal articles: 'New York (State). First Congregational Church' – Grafiati
Snowy Hydro Truck Jobs in All Sydney NSW - Sep 2024 | SEEK
Stark Cjis Court Docket
Lagniappemobile
How to Survive (and Succeed!) in a Fast-Paced Environment | Exec Learn
Fandafia
Rockin That Orange Jumpsuit Columbia County
Sam's Club Hiring Near Me
Personapay/Glens Falls Hospital
El Pulpo Auto Parts Houston
The Swarthmorean, 1932-05 | TriCollege Libraries Digital Collections
Fintechzoommortgagecalculator.live Hours
Guy Ritchie's The Covenant Showtimes Near Century 16 Eastport Plaza
How Long Ago Was February 28 2023
Cb2 South Coast Plaza
Latest Posts
Article information

Author: Roderick King

Last Updated:

Views: 6349

Rating: 4 / 5 (71 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Roderick King

Birthday: 1997-10-09

Address: 3782 Madge Knoll, East Dudley, MA 63913

Phone: +2521695290067

Job: Customer Sales Coordinator

Hobby: Gunsmithing, Embroidery, Parkour, Kitesurfing, Rock climbing, Sand art, Beekeeping

Introduction: My name is Roderick King, I am a cute, splendid, excited, perfect, gentle, funny, vivacious person who loves writing and wants to share my knowledge and understanding with you.